0

So, I keep getting a '429 too many requests' while running a script. After doing some research, I found that this is because the website it's fetching requires some sort of HTTP header with the request when making multiple requests. I haven't worked in python before, and I can't figure out how to attach a header to the HTTP request in this script? Thank you

Alright. StackExchange asked me to edit to explain how it was different from a similar question. The similar question "How do I send a custom header with urllib2 in a HTTP Request?" was someone asking when they were writing the script from scratch. I can't figure out for the life of me how the person who wrote the script did the request in the first place.

  • possible duplicate of [How do I send a custom header with urllib2 in a HTTP Request?](http://stackoverflow.com/questions/385262/how-do-i-send-a-custom-header-with-urllib2-in-a-http-request) – Nir Alfasi Mar 13 '15 at 03:41

1 Answers1

0

at line 41 & 42 of the grab.py, try modify the code like below:

import urllib2
req = urllib2.Request('http://www.example.com/')
req.add_header('Referer', 'http://www.python.org/')
resp = urllib2.urlopen(req)
content = resp.read()
  • Where in the [existing script](https://raw.githubusercontent.com/x89/Shreddit/nopraw/grab.py) do I put it? In between what lines? Do I need to replace any lines? – user227143 Mar 13 '15 at 03:48