Search code examples
pythonhttperror-handlingmechanizehttp-status-code-403

Way around HTTP 403 with python


im makeing a program that uses google to search but i cant becuase of the HTTP error 403 is there any way around it or anything im using mechanize to browse here is my code

from mechanize import Browser

inp = raw_input("Enter Word: ")
Word = inp

SEARCH_PAGE = "https://www.google.com/"

browser = Browser()
browser.open( SEARCH_PAGE )
browser.select_form( nr=0 )

browser['q'] = Word
browser.submit()

here is the error message

Traceback (most recent call last):
File "C:\Python27\Project\Auth2.py", line 16, in <module>
browser.submit()
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 541, in submit
return self.open(self.click(*args, **kwds))
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 203, in open
return self._mech_open(url, data, timeout=timeout)
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 255, in _mech_open
raise response
httperror_seek_wrapper: HTTP Error 403: request disallowed by robots.txt

please help and thank you


Solution

  • You can tell Mechanize to ignore the robots.txt file:

    browser.set_handle_robots(False)