[英]Connection aborted., error(104, 'Connection reset by peer') in Django
I have created an API in Django and inside that calling a third party API which accepts XML data.我在 Django 中创建了一个 API,并在其中调用了一个接受 XML 数据的第三方 API。 With 30 rows of XML it is working fine, for more rows throwing the error "Connection aborted.', error(104, 'Connection reset by peer')".
使用 30 行 XML 它工作正常,更多行抛出错误“连接中止。',错误(104,'连接重置由对等')”。 The third party also provided a UI so I can test that up to 5000 rows they are accepting and returning proper result.
第三方还提供了一个 UI,因此我可以测试他们接受的多达 5000 行并返回正确的结果。 The connection is not getting closed from either of the APIs.
连接未从任一 API 关闭。 What issue can it be?
可能是什么问题?
Expected Result预期结果
The post request should work properly for more data in the request as it is working fine for fewer data.对于请求中的更多数据,post 请求应该可以正常工作,因为它对于较少的数据可以正常工作。
Actual Result实际结果
ConnectionError at /v1/send-sms/
('Connection aborted.', error(104, 'Connection reset by peer'))
Request Method: POST
Request URL: http://example.com/v1/send-sms/
Django Version: 1.11
Exception Type: ConnectionError
Exception Value:
('Connection aborted.', error(104, 'Connection reset by peer'))
Exception Location: /home/user-135/sandbox/venv/local/lib/python2.7/site-packages/requests/adapters.py in send, line 490
Python Executable: /home/user-135/sandbox/venv/bin/python
Python Version: 2.7.12
Python Path:
['/home/user-135/public_html/MyProject',
'/home/user-135/sandbox/venv/lib/python2.7',
'/home/user-135/sandbox/venv/lib/python2.7/plat-x86_64-linux-gnu',
'/home/user-135/sandbox/venv/lib/python2.7/lib-tk',
'/home/user-135/sandbox/venv/lib/python2.7/lib-old',
'/home/user-135/sandbox/venv/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/user-135/sandbox/venv/local/lib/python2.7/site-packages',
'/home/user-135/public_html/MyProject',
'/home/user-135/public_html/MyProject']
Server time: Wed, 7 Mar 2018 10:55:19 +0530
Reproduction Steps繁殖步骤
import requests
recievers = ''
url = 'https://example.com/sms/'
for x in xrange(0, len(users)):
y = x + 1
body_content = body
phone = mobile_no
recievers = recievers + "<SMS>.......</SMS>"
xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<!DOCTYPE MESSAGE SYSTEM \"http://127.0.0.1:80/sms/ttr/sms.ptp\">\n<MESSAGE VER=\"1.2\">\n<USER USERNAME=\""+username+"\" PASSWORD=\""+password+"\" />"+recievers+"\n</MESSAGE>"
querystring = {"data": xml,"action":"send"}
headers = {'content-type': "application/xml"}
response = requests.request("POST", url, headers=headers, params=querystring)
Try replacing "params=querystring" with "data=querystring"尝试用“data=querystring”替换“params=querystring”
response = requests.request("POST", url, headers=headers, data=querystring)
params seems to be for GET requests and may by your request URL becomes too long after 30 lines of XML. params 似乎是针对 GET 请求的,并且在 30 行 XML 之后,您的请求 URL 可能会变得太长。
From docs at : http://docs.python-requests.org/en/master/user/quickstart/来自以下文档: http : //docs.python-requests.org/en/master/user/quickstart/
I had a similar case.我有一个类似的案例。 This error was given by the console when I accessed the delete method via the my API.
当我通过我的 API 访问 delete 方法时,控制台给出了这个错误。 The problem was solved by fixing the delete function in the
view.py
file, namely the status
argument of Response function that this method returned问题通过修复
view.py
文件中的delete函数解决,即该方法返回的Response函数的status
参数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.