33
votes

I am trying to follow Example 20.17.4.1. SocketServer.TCPServer from Python Docs. But I get an error:

ImportError: No module named 'ServerSocket'

I am using new version of Python and use IDLE for editing and executing the script. Need help to get rid of this error.

4
I tried also with import SocketServer instead of ServerSocket. No Luck :( @bamboon - Romaan
are you using python 2 or python 3? it has been renamed in python 3 to socketserver - Stephan Dollberg
I am using Python 3 and I am on windows 7. socketserver worked. EVERYTHING IN LOWER CASE. Thanks @bamboon - Romaan
@bamboon you should post that as an answer :) - iabdalkader
Also, Romaan, try to avoid reading the documentation of a software with a different major version number. Between python2.5 and python2.6 there are not so many differences, but between python2.x and python3.x there were many changes, and a lot of them were not backward compatible. The same is valid for any software. Major version change is usually related to backward incompatible changes. - Bakuriu

4 Answers

88
votes

The right name is SocketServer in Python2 and socketserver in Python3.

9
votes

If you are using python 3 it is available as socketserver (all lowercase)

2
votes

I got the same problem, which was resolved by uninstalling and installing the Flask and Werkzeug again

1) pip uninstall Flask 2) pip uninstall Werkzeug

3) pip install Flask 4) pip install Werkzeug

1
votes

In the code I have It already tried importing SocketServer and socketserver but neither work.

try:
    import SocketServer as socketserver
    from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
except ImportError:
    import socketserver
    from http.server import HTTPServer, BaseHTTPRequestHandler

However after I can this command it worked for me

$pip install Werkzeug --upgrade