預先感謝您提供的任何幫助。urlopen error [Errno 110] with https and python 2.7 on Ubuntu 12.10
我在ubuntu 12.10上安裝了python 2.7。我寫了一個基於其他職位,以測試HTTP和HTTPS連接的簡單腳本:
import urllib2, urllib
def set_proxy():
proxy = urllib2.ProxyHandler({'http': 'http://<proxyhost>:<proxyport>'})
opener = urllib2.build_opener(proxy, urllib2.HTTPHandler)
urllib2.install_opener(opener)
def http_call():
conn = urllib2.urlopen('http://www.whatismyip.com/')
return conn.read()
def https_call():
conn = urllib2.urlopen('https://chase.com/')
return conn.read()
set_proxy()
webpage = open('webpage.html', 'w')
return_str = https_call()
webpage.write(return_str)
webpage.close()
print ("check for output in webpage.html")
與HTTP測試工作正常,但以https產生以下輸出:
Traceback (most recent call last):
File "test.py", line 18, in <module>
return_str = https_call()
File "test.py", line 13, in https_call
conn = urllib2.urlopen('https://chase.com/')
File "/usr/lib/python2.7/urllib2.py", line 127, in urlopen
return _opener.open(url, data, timeout)
File "/usr/lib/python2.7/urllib2.py", line 401, in open
response = self._open(req, data)
File "/usr/lib/python2.7/urllib2.py", line 419, in _open
'_open', req)
File "/usr/lib/python2.7/urllib2.py", line 379, in _call_chain
result = func(*args)
File "/usr/lib/python2.7/urllib2.py", line 1219, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "/usr/lib/python2.7/urllib2.py", line 1181, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [Errno 110] Connection timed out>
這裏是我的設置:
[email protected]:/usr/local/pythonbrew# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.10
Release: 12.10
Codename: quantal
[email protected]:/usr/local/pythonbrew# python --version
Python 2.7.3
[email protected]:/usr/local/pythonbrew# openssl version
OpenSSL 1.0.1c 10 May 2012
我a similar, older post建議看到從源代碼重建用Python安裝了OpenSSL。我希望對我的問題有一個不同的解決方案,因爲這是更新的ubuntu/python版本,並且openssl已經在系統上。
任何指針讚賞。
注:在環境設定HTTPS_PROXY改變錯誤消息到以下(從錯誤編號110〜113):
urllib2.URLError: <urlopen error [Errno 113] No route to host>
順便說一句,下面還失敗:
[email protected]:/usr/local/pythonbrew# openssl s_client -connect encrypted.google.com:443
connect: No route to host
connect:errno=113
不知道是否有任何事情可以解決此問題。
在生產了幾個小時之後,我遇到了與https相同的問題。 Ubuntu 12.04 python 2.7。 – user1941407