简体   繁体   English

使用 Python requests.post() 方法在调用 REST API 时获取 HTTP 502,同时在 REST 客户端上工作正常

[英]Getting HTTP 502 on calling a time taking REST API using Python requests.post() method while same is working fine with REST client

I am calling a REST API which takes long time in processing like 2 minutes in python code using requests.post() method and getting HTTP 502 error in response.我正在调用一个 REST API,它在 python 代码中使用 requests.post() 方法处理需要很长时间,例如 2 分钟,并在响应中收到 HTTP 502 错误。 But calling same is working fine with different REST clients.但是调用相同的方法可以很好地处理不同的 REST 客户端。 What could be the possible reasons?可能的原因是什么? Following code has been used to call the API:以下代码已用于呼叫 API:

res = requests.post(url, proxies=proxies, headers=myheaders, data=data.encode('utf-8'), timeout=1000)

But for small inputs it works from python but not from long input.但是对于小输入,它从 python 开始工作,而不是从长输入开始工作。 For big inputs it is giving HTTP 502 error.对于大输入,它给出 HTTP 502 错误。 But everything is working fine with REST clients.但是 REST 客户一切正常。 What would be the possible point of error?可能的错误点是什么?

I faced similar issue and found out that the issue was caused not because of the request body but as a result of the response body being too big.我遇到了类似的问题,发现问题不是由于请求正文引起的,而是由于响应正文太大引起的。

I was using GraphQL to request data for the whole day and it kept on giving me 502 error.我一整天都在使用 GraphQL 请求数据,它一直给我 502 错误。 However, when I changed my request to provide the data only for 12 hours, it was successful in python.但是,当我把请求改成只提供12小时的数据时,python就成功了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM