gpt4 book ai didi

python - 连接中止。,Django 中的错误(104, 'Connection reset by peer')

转载 作者:太空宇宙 更新时间:2023-11-03 14:02:33 26 4
gpt4 key购买 nike

我在 Django 中创建了一个 API,并在其中调用接受 XML 数据的第三方 API。对于 30 行 XML,它工作正常,对于更多行,会抛出错误“连接已中止。”,错误(104,“连接由对等方重置”)”。第三方还提供了一个 UI,因此我可以测试他们接受的最多 5000 行并返回正确的结果。这两个 API 均未关闭连接。可能是什么问题?

预期结果

对于请求中的更多数据,post 请求应该可以正常工作,因为它对于较少的数据也可以正常工作。

实际结果

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

复制步骤

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)

最佳答案

尝试将“params=querystring”替换为“data=querystring”

 response = requests.request("POST", url, headers=headers, data=querystring)

params 似乎用于 GET 请求,并且可能会导致您的请求 URL 在 30 行 XML 后变得太长。

来自文档:http://docs.python-requests.org/en/master/user/quickstart/

关于python - 连接中止。,Django 中的错误(104, 'Connection reset by peer'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49145666/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com