gpt4 book ai didi

python - urllib HTTPS 请求 :

转载 作者:太空狗 更新时间:2023-10-29 18:19:56 27 4
gpt4 key购买 nike

我在 python3.4 上有一个脚本,它一直很好,直到我从中下载文件的网站决定使用 https,现在我收到错误但无法弄清楚如何检索文件。

我的脚本导入以下库并使用 urlretrive 获取先前的文件。因为它现在通过 302 重定向转发到 https。我遇到了一些错误。

import urllib
import urllib.request

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

我的错误:-

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>

最佳答案

很可能是您的 Python 安装或操作系统损坏了。

Python 仅在编译时支持 HTTPS 时才支持 HTTPS。但是,这应该是所有正常安装的默认设置。

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

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

请说明您是如何安装 Python 的。 Python.org 提供官方 Python 发行版

关于python - urllib HTTPS 请求 : <urlopen error unknown url type: https>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28376506/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com