You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Postman请求返回成功,Python相同请求返回504网关超时

Python POST请求返回504 Gateway Time-out但Postman成功的排查方案
  • 检查请求头差异
    Postman会自动填充User-Agent、Accept等默认请求头,而requests库默认的请求头可能不符合服务端预期。可以复制Postman中的完整请求头,添加到Python代码里:
import requests
url = "你的真实URL"

headers = {
    'User-Agent': 'PostmanRuntime/7.32.3',
    'Accept': '*/*',
    # 粘贴Postman中其他请求头
}

payload = {
     'token_master' : '你的真实token',
     'created_at' : '正确格式的日期'
}

response = requests.post(url, data=payload, headers=headers, timeout=360)
  • 确认Payload编码方式
    如果服务端期望接收JSON格式数据,而你用data参数传递(默认是form表单编码),就会导致请求异常。改用json参数传递Payload:
response = requests.post(url, json=payload, timeout=360)
  • 核对代理配置
    如果Postman使用了代理才能访问目标接口,Python代码也需要配置相同代理:
proxies = {
    'http': 'http://代理地址:端口',
    'https': 'https://代理地址:端口',
}
response = requests.post(url, data=payload, proxies=proxies, timeout=360)
  • 验证参数细节
    仔细核对created_at的日期格式(比如是否带时区、分隔符是否正确)、token_master是否完全匹配(无多余空格或字符),确保和Postman中的参数完全一致。

内容的提问来源于stack exchange,提问作者Henrique Veiga

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 04:14:52