【发布时间】:2020-10-30 19:13:03
【问题描述】:
我在 stackoverflow 上发现了一些类似的问题(1,2,3),但都没有解决我的问题。
网址类似于“https://example.com/api.php?foo=bar”。 使用以下命令将得到一个 json 字符串:
curl "https://example.com/api.php?foo=bar"
使用以下代码时返回 502 响应(错误的网关):
import requests
requests.get("https://example.com/api.php?foo=bar")
目前我正在使用以下代码作为解决方法,但我想知道为什么 requests.get() 不起作用。
import subprocess
subprocess.check_output(['curl','-s','https://example.com/api.php?foo=bar'])
【问题讨论】:
标签: python curl python-requests