'连接中止。', RemoteDisconnected('远端关闭连接无响应',)

问题描述 投票:0回答:2

我正在使用第 3 方 API 服务进行文本发送作业。

当我将大约 5000 个号码作为有效负载发送到 API 时,它工作正常。我注意到有时当有效负载计数超过 7000 或以上时。我收到来自 api 的以下错误代码响应。

'Connection aborted.', RemoteDisconnected('Remote end closed connection without response',)
msg_dict['test'] = test
   msg_dict_json = json.dumps(msg_dict)
   data = {
     'apikey': apikey,
     'data': msg_dict_json,
   }
   res = requests.post('https://api.txtlocal.com/bulk_json/', data=data)
   return res

样本数据对象:

data={
   "api_key": api_key,
   "data": '{"sender": "abc", "messages": [{"number": "+0000000000", "text": "some text"}], "test": true}'
}

data['data'] 可以超过 7000 个对象(这导致了问题)

我知道此 api 的每个 api 调用限制为 10000 个用户: https://api.txtlocal.com/bulk_json/ 所以我的有效负载计数始终保持在 10000 以下。

PS:请求不会回滚,即使我收到上述响应,短信也会发送给用户。只是我没有收到积极的回应,它抛出异常。

我还想提一下,我已经成功发送了 7 到 8000 条短信并得到了成功的回复,但现在它发送了这个问题。

如有任何帮助,我们将不胜感激,谢谢。

python django sms remote-connection textlocal
2个回答
0
投票

我不能使用评论,所以我使用答案。

Do you wait for the response ?

如果是这样,是否是超时问题?

谢谢。


0
投票

我尝试在标头中指定用户代理并且它有效。

    headers={
        'User-Agent': 'python-requests/2.31.0',
    }

您可以使用添加Python的默认标头

r = requests.utils.default_headers()

{
    'User-Agent': 'python-requests/2.31.0',
    'Accept-Encoding': 'gzip, deflate',
    'Accept': '*/*',
    'Connection': 'keep-alive',
}
© www.soinside.com 2019 - 2024. All rights reserved.