我们有一个Web服务(GET),它带有一个包含列表的复杂JSON, 如何设置它以便请求将生成的数据作为json而不是通过查询字符串发送?
这是当前代码的简化版本,我继续收到错误403:
def build_get_request_params(table_name):
data = {'table_data': table_name}
return data
def get_table_data_prefixed(table_name):
built = build_get_request_params(table_name)
response = requests.get("https://www.endpoint", data=json.dump(built))
print(response.json())
答案 0 :(得分:0)
通过将其添加为params
来修复:
def build_get_request_params(table_name):
data = {'table_name': table_name,
'prefixed': True
}
return data
def get_table_data_prefixed(table_name):
built = build_get_request_params(table_name)
response = requests.get("http://www.endpoint.com", params=built)
print(response.json())