import mechanize module to python script

社会主义新天地 提交于 2020-01-11 05:56:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!