Sravan
Sravan

Reputation: 553

Python urllib2 giving "network unreachable error" if the URL is https

I am trying to fetch some urls using urllib2 library.

a = urllib2.urlopen("http://www.google.com")
ret = a.read()

Code above is working fine, and giving expected result. But when I make the url https, it gives "network unreachable" error

a = urllib2.urlopen("https://www.google.com")
urllib2.URLError: <urlopen error [Errno 101] Network is unreachable>

Is there any problem with ssl? My python version is Python2.6.5. I am also behind an academic proxy server. I have the settings in bash file. Anyway, since http is opening proxy shouldn't be the problem here.

Upvotes: 3

Views: 6729

Answers (2)

Sravan
Sravan

Reputation: 553

The http url didn't give error because http_proxy variable was set already. By setting https_proxy the above error disappears.

export http_proxy = "http://{proxy-address}"

Set samething for https_proxy

export https_proxy = "http://{proxy-address}"

Upvotes: 1

Jharwood
Jharwood

Reputation: 1056

Normally the issue in cases like this is the proxy you are behind having an out of date or untrusted SSL certificate. urllib is fussier than most browsers when it comes to SSL and this is why you might be getting this error.

Upvotes: 1

Related Questions