在request.post()python3上收到错误

时间:2018-08-02 05:48:41

标签: python python-3.x post python-requests

我将通过python发送HTTP发布请求,最初该请求是针对android应用程序的。我可以使用Chrome的Postman扩展程序生成发帖请求并发送,但使用python时,会收到以下错误。

代码:

headers = {'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.0.2; Redmi Note 2 MIUI/V9.6.2.0.LHMMIFD)'}
r = requests.post("http://IP:PORT/PATH", data={'KEY': 'VALUE'}, headers=headers)

错误:

File "~/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
  chunked=chunked)
File "~/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 384, in _make_request
  six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "~/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 380, in _make_request
  httplib_response = conn.getresponse()
File "/usr/lib/python3.6/http/client.py", line 1331, in getresponse
  response.begin()
File "/usr/lib/python3.6/http/client.py", line 297, in begin
  version, status, reason = self._read_status()
File "/usr/lib/python3.6/http/client.py", line 258, in _read_status
  line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.6/socket.py", line 586, in readinto
  return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer

0 个答案:

没有答案