2 mjshuang mjshuang 于 2017.08.27 20:05 提问

ubuntu16.04下python打开http/https报错

ubuntu16.04下使用python中的urllib.urlopen()打开https报错IOError

 >>> import urllib
>>> urllib.urlopen('https://www.baidu.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/urllib.py", line 87, in urlopen
    return opener.open(url)
  File "/usr/local/lib/python2.7/urllib.py", line 210, in open
    return self.open_unknown(fullurl, data)
  File "/usr/local/lib/python2.7/urllib.py", line 222, in open_unknown
    raise IOError, ('url error', 'unknown url type', type)
IOError: [Errno url error] unknown url type: 'https'

报错信息:IOError: [Errno url error] unknown url type: 'https'

ubuntu16.04下使用python中的urllib2.urlopen()打开https/http报错

 >>> import urllib2
>>> urllib2.urlopen('https://www.baidu.com')           
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/local/lib/python2.7/urllib2.py", line 452, in _open
    'unknown_open', req)
  File "/usr/local/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 1266, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: https>
>>> urllib2.urlopen('http://www.baidu.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/local/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/local/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 1228, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/local/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
>>> 

报错信息:
urllib2.URLError:
urllib2.URLError:

这个要如何解决?求大神指点迷津,谢谢!

2个回答

RAM_MAM
RAM_MAM   2017.08.28 13:32

sudo apt-get install openssl #安装openssl

sudo apt-get install libssl-dev #安装openssl开发库

lv19980523
lv19980523   2017.08.29 14:17
Csdn user default icon
上传中...
上传图片
插入图片