【发布时间】:2022-01-06 18:21:49
【问题描述】:
我正在 python 中运行云函数以从 api 返回一些数据。该函数未执行,出现错误{'code': 400, 'message': 'Could not parse JSON'}。
这是我的代码:
import requests
import json
def my_function(request):
url = 'https://blablabla/detailed'
headers = {'X-Api-Key': 'XXXXXXXX',
'content-type': 'application/json'}
data = '{"dateRangeStart":"2020-05-10T00:00:00.000","dateRangeEnd":"2020-05-16T23:59:59.000","amountShown": "HIDE_AMOUNT","detailedFilter":{ "page":"1","pageSize":"50"}}'
#req = requests.post(url, headers=headers, json=data)
req = requests.post(url, headers=headers, data=json.dumps(data))
print(req.json())
我应该如何格式化我的数据变量?
【问题讨论】:
标签: python-3.x python-requests google-cloud-functions