adifire
adifire

Reputation: 610

GAE "No module named urllib"

Whenever I try to run a sample code on the 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'm not sure what the problem is, and I tried various fixes as in similar questions asked here.

The sample code:

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'm running on Mac OSX 10.6.8 (Snow Leopard) and using Python 2.7.3

Upvotes: 3

Views: 3319

Answers (3)

adifire
adifire

Reputation: 610

Funny thing is it's an inbuilt module (cgi.py) that's throwing up the error. And urllib is there! Can't figure why this is happening!

Also the Snow Leopard comes with python 2.6 installed to /system/Library/Frameworks/Python.framework/Versions/2.6 but the one I installed to is in /Library/Frameworks/Python.framework/Versions/2.7.

According to this, all I had to change is the Python reference in the preferences of GAE. This worked.

Upvotes: 2

ericcccc
ericcccc

Reputation: 152

Not sure how relevant this is, but the folder structure in the stack trace seems to imply that you are using Python 2.6, whereas you said that you have 2.7.3. Perhaps you need to run your script explicitly with your newest version of Python.

Upvotes: 2

Rishabh Manocha
Rishabh Manocha

Reputation: 2995

I'm not sure why the urllib import is not working, but in your sample code, you're not using that module, so you really shouldn't need to import it.

Upvotes: 0

Related Questions