WebSocket server in Python: 'module' object has no attribute 'AF_INET'
It appears that you've named your own file socket.py
, so when you import socket
, you're not getting the system library (it's just re-importing the file you're currently in - which has no AF_INET
symbol). Try renaming your file something like mysocket.py
.
I had the same problem, I was literally stuck here for hours, tried re installing it a million times, but found the solution.
1) Make sure the file name is not socket.py,
2) Change the directory, it will not work in the home directory due to some permission issues.
If you have by anychance saved the file as socket.py, do not copy the same file or rename it to something else, the problem will persist. What I advice you to do is, open a new folder in a different directory, write a simple socket code which involved AF_INET. Try to run it. It should work.
Even after changing the file name, if you are running the python from the terminal.
(you may get the same error)
Kindly
rm -rf socket.pyc
(previously compiled bytecode)