gpt4 book ai didi

python-2.7 - urllib IOError : [Errno socket error] [Errno 54] Connection reset by peer

转载 作者:太空宇宙 更新时间:2023-11-03 14:27:52 39 4
gpt4 key购买 nike

我正在尝试运行我的 python 代码,它显示以下内容:

IOError: [Errno socket error] [Errno 54] Connection reset by peer

这是我的代码:

import urllib

def dl_jpg(url, file_path, file_name):
full_path = file_path + file_name + '.jpg'
urllib.urlretrieve(url, full_path)

url = 'https://xxxxx'
file_name = '1'

dl_jpg(url, 'image/', file_name)

之前还可以,现在不行了。我不确定原因,我能想到的唯一区别是我更新了我的 macOS。我是编码新手,用谷歌搜索后仍然很困惑。我猜ssl中有一些问题。

我现在有

macOS 10.14.3

LibreSSL 2.6.5

python 2.7.10

有什么想法吗?非常感谢!

Traceback (most recent call last):
File "img3.py", line 10, in <module>
dl_jpg(url, 'image3/', file_name)
File "img3.py", line 5, in dl_jpg
urllib.urlretrieve(url, full_path)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 98, in urlretrieve
return opener.retrieve(url, filename, reporthook, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 245, in retrieve
fp = self.open(url, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 213, in open
return getattr(self, name)(url)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 443, in open_https
h.endheaders(data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1049, in endheaders
self._send_output(message_body)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 893, in _send_output
self.send(msg)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 855, in send
self.connect()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1274, in connect
server_hostname=server_hostname)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 352, in wrap_socket
_context=self)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 579, in __init__
self.do_handshake()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 808, in do_handshake
self._sslobj.do_handshake()

最佳答案

不幸的是,这是预装在 Mac OS 中的 python 2.7.10 的一个已知问题。如果您可以升级您的 python 版本并使用它来运行您的脚本,您会发现它会再次运行。

关于python-2.7 - urllib IOError : [Errno socket error] [Errno 54] Connection reset by peer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55444221/

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