Python Urllib Error 403
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings python requests 403 forbidden and policies of this site About Us Learn more about Stack Overflow
Python Requests 403 Error
the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation raise httperror(req.full_url, code, msg, hdrs, fp) urllib.error.httperror: http error 403: forbidden Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it urllib2 user agent only takes a minute: Sign up urllib2.HTTPError: HTTP Error 403: Forbidden up vote 41 down vote favorite 25 I am trying to automate download of historic stock data using python. The URL I am trying to open responds with a CSV file, but I am unable to open using urllib2. I have tried changing user agent as specified in few
Yolk Urllib2.httperror: Http Error 403: Must Access Using Https Instead Of Http
questions earlier, I even tried to accept response cookies, with no luck. Can you please help. Note: The same method works for yahoo Finance. Code: import urllib2,cookielib site= "http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/getHistoricalData.jsp?symbol=JPASSOCIAT&fromDate=1-JAN-2012&toDate=1-AUG-2012&datePeriod=unselected&hiddDwnld=true" hdr = {'User-Agent':'Mozilla/5.0'} req = urllib2.Request(site,headers=hdr) page = urllib2.urlopen(req) Error File "C:\Python27\lib\urllib2.py", line 527, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 403: Forbidden Thanks for your assistance python http urllib share|improve this question edited Nov 9 '12 at 7:14 Sudar 5,407124790 asked Nov 9 '12 at 6:51 kumar 8491810 Are you use windows as platform ? –Denis Nov 9 '12 at 7:08 add a comment| 2 Answers 2 active oldest votes up vote 77 down vote accepted By adding a few more headers I was able to get the data: import urllib2,cookielib site= "http://www.nseindia.com/live_market/dynaContent/live_watch/get_quote/getHistoricalData.jsp?symbol=JPASSOCIAT&fromDate=1-JAN-2012&toDate=1-AUG-2012&datePeriod=unselected&hiddDwnld=true" hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'Accept-Encoding': 'none', 'Accept-Language': 'en-US,en;q=0.8', 'Connection': 'keep-alive'} req = urllib2.Request(site, headers=hdr) try: page = urllib2.urlopen(req) except urllib2.HTTPError, e: print e.fp.read() content = page.read() print content Actually, it works with just this one additi
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of python urllib headers this site About Us Learn more about Stack Overflow the company Business Learn python requests user agent more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Python User-agent
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up http://stackoverflow.com/questions/13303449/urllib2-httperror-http-error-403-forbidden HTTP error 403 in Python 3 Web Scraping up vote 13 down vote favorite 5 I was trying to scrap a website for practice, but I kept on getting the HTTP Error 403 (does it think I'm a bot)? Here is my code: #import requests import urllib.request from bs4 import BeautifulSoup #from urllib import urlopen import re webpage = urllib.request.urlopen('http://www.cmegroup.com/trading/products/#sortField=oi&sortAsc=false&venues=3&page=1&cleared=1&group=1').read findrows = re.compile('
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies http://stackoverflow.com/questions/16250050/python-http-error-403-forbidden of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a error 403 minute: Sign up Python HTTP Error 403 Forbidden up vote 3 down vote favorite I am a bit of a Python Newbie, and I've just been trying to get some code working. Below is the code, and also the nasty error I keep getting. import pywapi import string google_result = pywapi.get_weather_from_google('Brisbane') print google_result def getCurrentWather(): city = google_result['forecast_information']['city'].split(',')[0] print "It is " python requests 403 + string.lower(google_result['current_conditions']['condition']) + " and " + google_result['current_conditions']['temp_c'] + " degree centigrade now in "+ city+".\n\n" return "It is " + string.lower(google_result['current_conditions']['condition']) + " and " + google_result['current_conditions']['temp_c'] + " degree centigrade now in "+ city def getDayOfWeek(dayOfWk): #dayOfWk = dayOfWk.encode('ascii', 'ignore') return dayOfWk.lower() def getWeatherForecast(): #need to translate from sun/mon to sunday/monday dayName = {'sun': 'Sunday', 'mon': 'Monday', 'tue': 'Tuesday', 'wed': 'Wednesday', ' thu': 'Thursday', 'fri': 'Friday', 'sat': 'Saturday', 'sun': 'Sunday'} forcastall = [] for forecast in google_result['forecasts']: dayOfWeek = getDayOfWeek(forecast['day_of_week']); print " Highest is " + forecast['high'] + " and "+ "Lowest is " + forecast['low'] + " on " + dayName[dayOfWeek] forcastall.append(" Highest is " + forecast['high'] + " and "+ "Lowest is " + forecast['low'] + " on " + dayName[dayOfWeek]) return forcastall Now is the error: Traceback (most recent call last): File "C:\Users\Alex\Desktop\JAVIS\JAISS-master\first.py", line 5, in