urlopen error [Errno 110] with https and python 2.7 on ubuntu 12.10

匿名 (未验证) 提交于 2019-12-03 00:57:01

问题:

Thank you in advance for any help provided.

I am on ubuntu 12.10 with python 2.7 installed. I wrote a simple script based on other posts to test http and https connections:

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") 

The test with http works fine, but with https produces the following output:

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> 

Here is my setup:

root@sc11137376:/usr/local/pythonbrew#  lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description:    Ubuntu 12.10 Release:        12.10 Codename:       quantal  root@sc11137376:/usr/local/pythonbrew# python --version Python 2.7.3  root@sc11137376:/usr/local/pythonbrew# openssl version OpenSSL 1.0.1c 10 May 2012 

I saw in a similar, older post suggestions to rebuild python from source with openssl installed. I am hoping there is a different solution to my problem, since this is much newer ubuntu/python version and openssl is already on the system.

Any pointers appreciated.

Note: Setting HTTPS_PROXY in the environment changed the error message to the following (from error number 110 to 113):

urllib2.URLError: <urlopen error [Errno 113] No route to host> 

Btw, the following also fails:

root@sc11137376:/usr/local/pythonbrew# openssl s_client -connect encrypted.google.com:443 connect: No route to host connect:errno=113 

Not sure if there is anything I can do to resolve this problem.

回答1:

URLError:urlopen error [Errno 113] No route to host

I had a same kind of error : i wanted to execute some scripts remotely on machine B from machine A (which does some browser automation stuff) and finally i had the error as stated above later i disabled the firewall setting for the HTTPS.

How i disabled the fire wall setting on RHEL6.4 ? - click settings (on left side of the panel) > Administration > Firewall > on "Firewall Configuration" window : check the "secure WWW (HTTPS)" -(you need to be root user) >> click "Apply" >> click the disable button.

later i was able to execute the scripts on remote machine B without any hassle.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!