Urllib2. Httperror:http Error 403:forbidden

Source: Internet
Author: User

This problem is mainly not headers, add some content can be

Example:

# -*-coding:utf-8-*- Import Urllib2site " 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  "= {'user-agent':'mozilla/5.0'  = Urllib2. Request (site,headers== Urllib2.urlopen (req)

An error occurred in the header:

Join headers:

1 ImportUrllib22 3Sizes"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"4HDR = {'user-agent':'mozilla/5.0 (X11; Linux x86_64) applewebkit/537.11 (khtml, like Gecko) chrome/23.0.1271.64 safari/537.11',5        'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',6        'Accept-charset':'iso-8859-1,utf-8;q=0.7,*;q=0.3',7        'accept-encoding':'None',8        'Accept-language':'en-us,en;q=0.8',9        'Connection':'keep-alive'}Ten  Onereq = Urllib2. Request (Site, headers=HDR) A  - Try: -page =Urllib2.urlopen (req) the exceptUrllib2. Httperror, E: -     PrintE.fp.read () -  -Content =Page.read () + PrintContent

See if it's successful?!

Urllib2. Httperror:http Error 403:forbidden

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.