views:

1400

answers:

4

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

A: 

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?

Nick Johnson
I am also trying to use mechanize in GAE and this is the traceback. http://pastebin.ca/1720324 Any sort of help will be appreciated. Thanks in advance.
aatifh
+2  A: 

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.

Matthew Trevor
A: 

Thanks All for the prompt reply.

Here is the log content got from the GAE,

: No module named ClientForm Traceback (most recent call last): File "/base/data/home/apps/seoapp/1.28/main.py", line 10, in import mechanize File "/base/data/home/apps/seoapp/1.28/mechanize/init.py", line 85, in from _mechanize import version File "/base/data/home/apps/seoapp/1.28/mechanize/_mechanize.py", line 15, in from _useragent import UserAgentBase File "/base/data/home/apps/seoapp/1.28/mechanize/_useragent.py", line 16, in import _opener File "/base/data/home/apps/seoapp/1.28/mechanize/_opener.py", line 23, in import _http File "/base/data/home/apps/seoapp/1.28/mechanize/_http.py", line 22, in from _html import unescape, unescape_charref File "/base/data/home/apps/seoapp/1.28/mechanize/_html.py", line 12, in import sgmllib, ClientForm

mechanize uses the clientform module, you need to make sure that clientform is also on the PYTHONPATH.
codeape
A: 

I can finally manage with GAE's urlfetch instead of mechanizer. I can able to retrieve the response using the above said utility.

Thanks all for the great timely help.

^Ponmalar

Can you show me your implementation? I am facing the same problem
aatifh