如何在 requests.get 中运行 JSON 脚本以从 Alloy 中获取表?

问题描述 投票:0回答:1

我正在尝试向运行 json 代码并输出数据的合金发送 json 请求。

''' aqs = {“aqs”:{ "type": "加入", “特性”: { “属性”: [ “attributes_itemsTitle”, “attributes_itemsSubtitle” ], “集合代码”:[ “居住” ], "dodiCode": "designs_nlpgPremises", “加入属性”:[] }, “孩子们”: [ { “类型”:“和”, “孩子们”: [ { "type": "等于", “孩子们”: [ { “类型”:“属性”, “特性”: { "attributeCode": "attributes_premises邮政编码" } }, { “类型”:“字符串”, “特性”: { “价值”: [ “BS5 6AP” ] } } ] } ] } ] }}

headers = { 'X-Authentication-Token' : token }
urlBase = 'https://uk.alloyapp.io/api/'
requestURL = urlBase + 'aqs/join?token=' + token
response = requests.get(requestURL, headers = headers, data=json.dumps(aqs))
print(response.text)

当我运行此代码时,出现此错误

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
This distribution is not configured to allow the HTTP request method that was used for 
this request. The distribution supports only cachable requests.
We can't connect to the server for this app or website at this time. There might be too 
much traffic or a configuration error. Try again later, or contact the app or website 
owner.
<BR clear="all">
If you provide content to customers through CloudFront, you can find steps to 
troubleshoot and help prevent this error by reviewing the CloudFront documentation.
<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: txrBxRox0BvgpLAFSbqvBztjhYsUmUzWdjizayD20tinETqt85fG==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>
python json python-requests
1个回答
0
投票

根据API文档(https://api.uk.alloyapp.io/swagger/ui/index.html?url=/swagger#/Aqs/Aqs_Join),你应该使用

POST
(而不是
GET
) :

import requests

payload = {
    "aqs": {"type": "Query", "properties": {}, "children": ["string"]},
    "parameterValues": [{"name": "string", "value": {}}],
}

api_url = "https://api.uk.alloyapp.io/api/aqs/join"

headers = {"X-Authentication-Token": "<REDACTED>"}

data = requests.post(api_url, json=payload, headers=headers).json()
print(data)
© www.soinside.com 2019 - 2024. All rights reserved.