gpt4 book ai didi

python - 使用 API 在 Redash 上创建新查询

转载 作者:行者123 更新时间:2023-12-05 06:25:24 28 4
gpt4 key购买 nike

我设法将查询导入另一个帐户。我使用了 Redash 提供的端点 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

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

url = path, api = user api, f = filename, query_id = 本地桌面文件的query_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)

我收到 response.status_code 500。我的代码有什么问题吗?我该如何解决?

最佳答案

供将来引用:-) 这是一个创建新查询的 python POST:

    payload = {
"query":query, ## the select query
"name":"new query name",
"data_source_id":1, ## can be determined from the /api/data_sources end point
"schedule":None,
"options":{"parameters":[]}
}
res = requests.post(redash_url + '/api/queries',
headers = {'Authorization':'Key YOUR KEY'},
json=payload)

(通过与@JohnDenver 的线下讨论找到了解决方案)

关于python - 使用 API 在 Redash 上创建新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57160268/

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