gpt4 book ai didi

python - 从 Python 到 Azure 的 REST API 调用问题

转载 作者:行者123 更新时间:2023-12-02 08:30:56 28 4
gpt4 key购买 nike

我正在使用 HTML 表单获取用于 Azure REST API 调用的参数。

我的代码

@app.route('/storageaccountcreate', methods = ['POST', 'PUT'])
def storageaccountcreate():
name = request.form['storageaccountname']
resourcegroup = request.form['resourcegroup']
subscriptionId = request.form['subscriptionId']
location = request.form['location']
sku = request.form['sku']
keys = [name, resourcegroup, subscriptionId, location, sku]
api_json = {keys: request.form[key] for key in keys}
url = 'https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2019-06-01'
r = requests.put((url),data=(api_json))
print(r.text)
return r.text

尝试使用此代码时出现以下错误

Bad Request
The browser (or proxy) sent a request that this server could not understand.

VSC 中的调试也显示以下内容

Photo of error

如果您有任何有帮助的信息,我将不胜感激!

最佳答案

Python 不会在常规字符串中插入值:

url = 'https://management.azure.com/subscriptions/{subscriptionId}/...'
# ^^^^^^^^^^^^^^^^

假设您使用的是 Python 3.6 或更高版本,请使用 f-string启用插值:

url = f'https://management.azure.com/subscriptions/{subscriptionId}/...'
# ^ here

关于python - 从 Python 到 Azure 的 REST API 调用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61089999/

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