urllib2 error

Kushal Kumaran kushal.kumaran+python at gmail.com
Wed Nov 17 07:01:26 EST 2010


On Wed, Nov 17, 2010 at 5:18 PM, asit <lipun4u at gmail.com> wrote:
> I have this piece of code
>
> import urllib2
>
> proc_url = 'http://www.nse-india.com/content/historical/EQUITIES/2001/
> JAN/cm01JAN2001bhav.csv.zip'
> print 'processing....', proc_url
> req = urllib2.Request(proc_url)
> res = urllib2.urlopen(req)
>
> when i run this...following error comes
>
> Traceback (most recent call last):
> <snipped detailed trace>
> HTTPError: HTTP Error 403: Forbidden
>

The web server is probably trying to forbid downloads using automated
tools by examining the user agent header (downloading using wget also
fails, for example).  You can work around that by setting the
User-Agent header to the same value as a browser that works.

The urllib2 documentation covers how to set headers in requests.

-- 
regards,
kushal



More information about the Python-list mailing list