GAE "No module named urllib"

Whenever I try to run sample code in GAE via python, I get this error

File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/tools/dev_appserver_import_hook.py", line 1665, in LoadModuleRestricted
    description)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/cgi.py", line 31, in <module>
    import urllib
ImportError: No module named urllib
INFO     2012-04-15 04:44:54,345 dev_appserver.py:2884] "GET / HTTP/1.1" 500 -

I am not sure what the problem is, and I tried various fixes, as in similar questions asked here.

Code example:

import webapp2
import urllib

class MainPage(webapp2.RequestHandler):
  def get(self):
      self.response.headers['Content-Type'] = 'text/plain'
      self.response.out.write('Hello, webapp World!')

app = webapp2.WSGIApplication([('/', MainPage)],
                              debug=True)

I work on Mac OSX 10.6.8 (Snow Leopard) and using Python 2.7.3

+3
source share
3 answers

Not sure how appropriate this is, but the folder structure in the stack trace implies that you are using Python 2.6, whereas you said that you had 2.7.3. Perhaps you need to explicitly run your script using your latest version of Python.

+2
source

, (cgi.py), . ! , !

Snow Leopard python 2.6, /system/Library/Frameworks/Python.framework/Versions/2.6, , , /Library/Frameworks/Python.framework/Versions/2.7.

, , Python GAE. .

+2

I'm not sure why the import urllibdoes not work, but in your sample code you are not using this module, so you really do not need to import it.

0
source

All Articles