使用API在Redash上创建新查询

2024-05-16 02:43:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我设法将查询导入另一个帐户。我使用了Redash给出的endpoint POST函数,它有点只适用于“修改/替换”:https://github.com/getredash/redash/blob/5aa620d1ec7af09c8a1b590fc2a2adf4b6b78faa/redash/handlers/queries.py#L178

所以实际上,如果我想导入一个新的查询,我应该怎么做?我想创建一个在我的帐户上不存在的新查询。我在看https://github.com/getredash/redash/blob/5aa620d1ec7af09c8a1b590fc2a2adf4b6b78faa/redash/handlers/queries.py#L84

下面是我在查询不存在时创建新查询的函数。

url=路径,api=用户api,f=文件名,query_id=本地桌面中文件的查询_id

def new_query(url, api, f, query_id):
    headers ={'Authorization': 'Key {}'.format(api), 'Content-Type': 'application/json'}
    path = "{}/api/queries".format(url)
    query_content = get_query_content(f)
    query_info = {'query':query_content}
    print(json.dumps(query_info))
    response = requests.post(path, headers = headers, data = json.dumps(query_info))
    print(response.status_code)

我得到了响应状态代码500我的代码有什么问题吗?我该怎么修?


Tags: 函数httpsinfogithubcomapiidjson