import mechanize module to python script

2019-02-17 22:41发布

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

2条回答
欢心
2楼-- · 2019-02-17 22:54

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.

查看更多
一夜七次
3楼-- · 2019-02-17 22:54

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?

查看更多
登录 后发表回答