Python请求我得到连接重置错误

时间:2018-10-12 15:36:49

标签: python python-requests

我使用请求,以便从网页中获取一些图像。 但是过了一会儿,我收到连接重置错误。我应该如何更改以下代码? 我相信Python请求库中的requests.Session()对象可以使用持久连接来完成这项工作。

import csv
import requests

with open('urls.csv') as csvfile:
    csvrows = csv.reader(csvfile, delimiter=',', quotechar='"')
    for row in csvrows:
        filename = row[0]
        url = row[1]
        print(url)
        result = requests.get(url, stream=True)
        if result.status_code == 200:
            image = result.raw.read()
            open(filename,"wb").write(image)

我得到的错误:

lib/python3.6/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 417, in wrap_socket
    cnx.do_handshake()
  File "/home/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1426, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "/home/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1166, in _raise_ssl_error
    raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (104, 'ECONNRESET')

0 个答案:

没有答案