Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mockserver server.py does not work in Python 3 #979

Closed
systemcatch opened this issue Jan 5, 2018 · 6 comments
Closed

Mockserver server.py does not work in Python 3 #979

systemcatch opened this issue Jan 5, 2018 · 6 comments

Comments

@systemcatch
Copy link
Collaborator

mockserver_1  |   File "../server.py", line 5, in <module>
mockserver_1  |     from SimpleHTTPServer import SimpleHTTPRequestHandler, BaseHTTPServer
mockserver_1  | ModuleNotFoundError: No module named 'SimpleHTTPServer'

Looks like some modules have been reorganized in Python 3. Hopefully this is just a matter of updating the imports.

@corradio
Copy link
Member

corradio commented Jan 6, 2018 via email

@corradio
Copy link
Member

corradio commented Jan 6, 2018

@systemcatch
Copy link
Collaborator Author

Running 2to3 made just one change to server.py.

-from SimpleHTTPServer import SimpleHTTPRequestHandler, BaseHTTPServer
+from http.server import SimpleHTTPRequestHandler, BaseHTTPServer

But I still get ImportError: cannot import name 'BaseHTTPServer' when running python3 server.py
Looks like 2to3 can't auto fix this.

@corradio
Copy link
Member

corradio commented Jan 6, 2018

According to this:
https://stackoverflow.com/questions/23264569/python-3-x-basehttpserver-or-http-server
apparently BaseHTTPServer is now http.server.
Maybe the correct import is

from http.server import SimpleHTTPRequestHandler, HTTPServer

More info:
https://docs.python.org/3/library/http.server.html

Hopefully this can point you in the right direction. Unfortunately I don't have time to fix this right now but will be able to after Wednesday.

@systemcatch
Copy link
Collaborator Author

Yeah I've been looking through those docs. I've made the following changes so that it will run on the commandline.

from http.server import SimpleHTTPRequestHandler, HTTPServer, test
if __name__ == '__main__':
    test(CORSRequestHandler, HTTPServer)
chris@ThinkPad:~/electricitymap/mockserver$ python3 server.py 
Serving HTTP on 0.0.0.0 port 8000 ...

But no luck getting it to work on the map yet.

@corradio
Copy link
Member

corradio commented Jan 6, 2018

I think you need to do a docker-compose build first in order to make sure to rebuild the docker image using python 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants