美文网首页
python requests请求上传大文件报BrokenPip

python requests请求上传大文件报BrokenPip

作者: Ivanlfli | 来源:发表于2022-05-18 10:15 被阅读0次

    问题:

    请求上传大文件报BrokenPipeError(32, 'Broken pipe')

    Traceback (most recent call last):
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
        httplib_response = self._make_request(
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/urllib3/connectionpool.py", line 392, in _make_request
        conn.request(method, url, **httplib_request_kw)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1252, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1298, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1247, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1046, in _send_output
        self.send(chunk)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 968, in send
        self.sock.sendall(data)
    BrokenPipeError: [Errno 32] Broken pipe
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/requests/adapters.py", line 440, in send
        resp = conn.urlopen(
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/urllib3/connectionpool.py", line 726, in urlopen
        retries = retries.increment(
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/urllib3/util/retry.py", line 410, in increment
        raise six.reraise(type(error), error, _stacktrace)
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/urllib3/packages/six.py", line 734, in reraise
        raise value.with_traceback(tb)
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
        httplib_response = self._make_request(
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/urllib3/connectionpool.py", line 392, in _make_request
        conn.request(method, url, **httplib_request_kw)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1252, in request
        self._send_request(method, url, body, headers, encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1298, in _send_request
        self.endheaders(body, encode_chunked=encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1247, in endheaders
        self._send_output(message_body, encode_chunked=encode_chunked)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 1046, in _send_output
        self.send(chunk)
      File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py", line 968, in send
        self.sock.sendall(data)
    urllib3.exceptions.ProtocolError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "/Users/ivanli/git/own/ci-test/tencent/pic.py", line 216, in <module>
        run()
      File "/Users/ivanli/git/own/ci-test/tencent/pic.py", line 211, in run
        res = CIApi().req(uri=f"/{fname}", method="put", body=res_body, headers=headers)
      File "/Users/ivanli/git/own/ci-test/tencent/pic.py", line 182, in req
        rsp = HttpReq(method=method, url=url, data=body, headers=headers).req()
      File "/Users/ivanli/git/own/ci-test/tencent/pic.py", line 48, in req
        return s.send(s.prepare_request(self))
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/requests/sessions.py", line 645, in send
        r = adapter.send(request, **kwargs)
      File "/Users/ivanli/git/own/ci-test/lib/python3.8/site-packages/requests/adapters.py", line 501, in send
        raise ConnectionError(err, request=request)
    requests.exceptions.ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))
    
    Process finished with exit code 1
    

    解决:

    原因是用的urllib3库版本是1.25.x,这个版本有bug,需要升到1.26.x
    https://github.com/urllib3/urllib3/pull/1524

    wecom-temp-11eda5f4582434a001ad3250ce387916.png

    相关文章

      网友评论

          本文标题:python requests请求上传大文件报BrokenPip

          本文链接:https://www.haomeiwen.com/subject/qjzourtx.html