Kevin
Kevin

Reputation: 3379

Submitting a form with mechanize HTTP Error 500

This is my first time using mechanize and I'm trying to fill out a form with mechanize

Here are my browser options:

br.set_handle_equiv(True)
br.set_handle_gzip(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)


cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)


br.addheaders = br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-    US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

I fill out the form with valid values and hit br.submit() but it gives me HTTP: Error 500: Internal Server Error. I'm assuming it's detecting that it's a bot or something hitting the submit? But I figured that's what the addheaders was suppose to take care of.

Upvotes: 0

Views: 1113

Answers (1)

Alexander Zh
Alexander Zh

Reputation: 111

You can use http://grablib.org/docs/, it is much easier and more efficient. Try it. Install on linux:

pip install pycurl lxml

pip install grab

from grab import Grab

g = Grab()
g.go('http://google.com') # go to google.com
g.choose_form(0)  #form number
g.set_input('q', 'test')  # 'q'-input name, 'test' - search query
g.submit()  # send request
print g.xpath_list('//a/text()') # view xpath result link list 

Sorry for my english.

Upvotes: 1

Related Questions