urllib2 error


A

asit

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):
File "C:/Python26/reqnse.py", line 92, in <module>
res = urllib2.urlopen(req)
File "C:\Python26\lib\urllib2.py", line 124, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python26\lib\urllib2.py", line 395, in open
response = meth(req, response)
File "C:\Python26\lib\urllib2.py", line 508, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python26\lib\urllib2.py", line 433, in error
return self._call_chain(*args)
File "C:\Python26\lib\urllib2.py", line 367, in _call_chain
result = func(*args)
File "C:\Python26\lib\urllib2.py", line 516, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 403: Forbidden

would anyone help me why ??
 
Ad

Advertisements

K

Kushal Kumaran

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.
 
Ad

Advertisements

A

asit dhal

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,
Asit Kumar Dhal
TCS, Mumbai
blog: http://asitdhal.blogspot.com/

Thanx...it worked
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top