Urllib2.URLError: <urlopen error Could not connect to tunnel: 403 Tunnel or SSL Forbidden>

Basically, I'm trying to use python urllib2. I want to connect and get data from the site. The problem is that I get an error

urllib2.URLError: <urlopen error Tunnel connection failed: 403 Tunnel or SSL Forbidden>

After repeating my experiments with this library, I found that the code I wrote worked well with https: // sites , but not with http: // sites . I read a few earlier stack overflow questions suggesting to add a title User-Agent:Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7(to trick the title).

I did it, but still failed.

After that I read this urllib2.HTTPError: HTTP Error 403: Forbidden

I tried it too, but it didn't work.

Here is my code

import urllib2
url = "http://the_site_i_want_to_connect"
hdr = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
req = urllib2.Request(url , headers=hdr)
p = urllib2.urlopen(req).read()
print p

PS: , https

, ! !

+4
1

-, ,

+2

All Articles