I am trying to automate a process on a website using the python mechanize module.
With the following code, I am refreshing the site until I find a link that I want to follow:
for link in br.links():
valuable = filter(lambda tpl: tpl[0]=='href', link.attrs)
if len(valuable) == 0:
continue
if 'book.php' in valuable[0][1]:
print link
req = br.follow_link(link)
file_handler = open("level2.html", "w")
file_handler.write(br.response().read())
file_handler.close()
not_done = False
break
As soon as I find the link containing "book.php", the application crashes and I get the following error:
File "/home/max/Dokumente/dev/main.py", line 43, in run req = br.follow_link(link)
File "build/bdist.linux-x86_64/egg/mechanize/_mechanize.py", line 569, in follow_link
File "build/bdist.linux-x86_64/egg/mechanize/_mechanize.py", line 203, in open
File "build/bdist.linux-x86_64/egg/mechanize/_mechanize.py", line 255, in _mech_open
mechanize._response.httperror_seek_wrapper: HTTP Error 428: Precondition failed
What does that mean? I can't really figure it out. How can I resolve this error?