问题
I tried to import mechanize module to my python script like this,
from mechanize import Browser
But, Google appengine throws HTTP 500 when accessing my script.
To make things more clear, Let me give you the snapshot of my package structure,
root
....mechanize(where all the mechanize related files there)
....main.py
....app.yaml
....image
....script
Can anyone help me out to resolve this issue?
Thanks, Ponmalar
回答1:
The mechanize main page says:
mechanize.Browser is a subclass of mechanize.UserAgentBase, which is, in turn, a subclass of urllib2.OpenerDirector
My understanding is that urllib2 is one of the sandboxed modules in GAE, with its functionality being replaced by the Google-provided urlfetch. You'd need to re-implement the mechanize.UserAgentBase class to use urlfetch, if that's at all possible.
回答2:
When GAE throws a 500, you can see the actual error in the logs on your admin console. If that doesn't help, paste it here and we'll help further.
Also, does it work on the dev_appserver?
来源:https://stackoverflow.com/questions/275980/import-mechanize-module-to-python-script