gpt4 book ai didi

python - 将 POST 从请求转换为 GAE urlfetch

转载 作者:太空宇宙 更新时间:2023-11-03 13:16:27 25 4
gpt4 key购买 nike

我正在使用 PayPal 付款。以下是它如何与 requests 一起正常工作:

res = requests.post(get_payment_info_url, headers=headers, data=params)
res_data = res.json()

但是当我尝试使用 urlfetch 执行相同的请求时,它给了我一个错误(来自 PayPal 的 200 响应,但付款失败):

res = urlfetch.fetch(url=make_payment_url, payload=params, method=urlfetch.POST, headers=headers)
res_data = json.loads(res)

{u'responseEnvelope': {u'timestamp': u'2015-02-15T23:21:52.729-08:00', u'ack': u'Failure', u'build': u'15089777', u'correlationId': u'e202988541fde'},
u'error': [{u'domain': u'PLATFORM', u'message': u'Invalid request: {0}', u'severity': u'Error', u'subdomain':
u'Application', u'category': u'Application', u'errorId': u'580001'}]}

似乎谷歌正在剥离标题或其他东西?如果 Google 这样做,我该如何提出这个请求?

最后,是否有任何理由在 requests 上使用 urlfetch(我已经在本地将其导入到我的 GAE 项目中?Requests 似乎更容易和“友好”使用。

最佳答案

为此,需要对有效负载进行 urlencoded。这是有效的:

res2 = urlfetch.fetch(
url,
headers=headers,
method='POST',
payload=urllib.urlencode(params)
)
res2_data = json.loads(res2.content)

关于python - 将 POST 从请求转换为 GAE urlfetch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28536376/

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