Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

python - urllib HTTPS request: <urlopen error unknown url type: https>

I have a script on python3.4 and it has been fine until the website I download the file from decides to use https and now I am getting error but can't figure out how I can retrive the file.

My script import the following library and uses the urlretrive to get the file previously. Since it is now forwarded to https with 302 redirection. I am getting some error.

import urllib
import urllib.request

urllib.request.urlretrieve("http://wordpress.org/latest.tar.gz", "/thefile.gz")

My error:-

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/urllib/request.py", line 178, in urlretrieve
    with contextlib.closing(urlopen(url, data)) as fp:
  File "/usr/local/lib/python3.4/urllib/request.py", line 153, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python3.4/urllib/request.py", line 461, in open
    response = meth(req, response)
  File "/usr/local/lib/python3.4/urllib/request.py", line 571, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/local/lib/python3.4/urllib/request.py", line 493, in error
    result = self._call_chain(*args)
  File "/usr/local/lib/python3.4/urllib/request.py", line 433, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.4/urllib/request.py", line 676, in http_error_302
    return self.parent.open(new, timeout=req.timeout)
  File "/usr/local/lib/python3.4/urllib/request.py", line 455, in open
    response = self._open(req, data)
  File "/usr/local/lib/python3.4/urllib/request.py", line 478, in _open
    'unknown_open', req)
  File "/usr/local/lib/python3.4/urllib/request.py", line 433, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python3.4/urllib/request.py", line 1257, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: https>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Most likely your Python installation or operating system is broken.

Python has only support for HTTPS if it was compiled with HTTPS support. However, this should be the default for all sane installations.

HTTPS support is only available if the socket module was compiled with SSL support.

https://docs.python.org/3/library/http.client.html

Please clarify how you installed Python. Official Python distributions are available at python.org


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...