Python请求:对于多部分文件POST

时间:2017-11-30 09:32:15

标签: python python-requests

与这个悬而未决的问题相同的问题:Connection reset for multi-part file upload using requests python library

我将多部分表单请求发布到本地运行的服务器,它适用于小文件,但如果我尝试发送更大的文件(~20MB),则会出现以下错误:

File "~/.virtualenvs/sound-api/lib/python3.5/site-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
File "~/.virtualenvs/sound-api/lib/python3.5/site-packages/urllib3/connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
File "/usr/lib/python3.5/http/client.py", line 936, in _send_output
    self.send(message_body)
File "/usr/lib/python3.5/http/client.py", line 905, in send
    self.sock.sendall(datablock)
ConnectionResetError: [Errno 104] Connection reset by peer

以下是发出请求的代码:

files = {
    'file': my_file
}
data = {
    'parameter': 'some data'
}
session = requests.Session()
result = self.session.post(
    url,
    files=files,
    data=data
)
return result

我在virtualenv中使用请求2.18.4运行Python 3.5.2。 我错过了一些设置或库以允许我发送更大的文件吗?

0 个答案:

没有答案