我正在尝试运行我的python代码,它显示以下内容:
IOError:[Errno套接字错误] [Errno 54]由对等方重置连接
这是我的代码:
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。我是编码新手,但在搜寻Google之后仍然很困惑。我想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()
答案 0 :(得分:0)
不幸的是,这是python 2.7.10的一个已知问题,它已预装在Mac OS中。如果您可以升级python版本并使用它运行脚本,则会发现它会再次运行。