Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python请求-Azure RM API返回200个状态代码,但内容中返回400个_Python_Python 2.7_Azure_Python Requests_Azure Resource Manager - Fatal编程技术网

Python请求-Azure RM API返回200个状态代码,但内容中返回400个

Python请求-Azure RM API返回200个状态代码,但内容中返回400个,python,python-2.7,azure,python-requests,azure-resource-manager,Python,Python 2.7,Azure,Python Requests,Azure Resource Manager,我有一些代码,我试图根据Azure的资源管理器REST API进行身份验证 import json import requests tenant_id = "TENANT_ID" app_id = "CLIENT_ID" password = "APP_SECRET" token_endpoint = 'http://login.microsoftonline.com/%s/oauth2/token' % tenant_id management_uri = 'https://managem

我有一些代码,我试图根据Azure的资源管理器REST API进行身份验证

import json
import requests

tenant_id = "TENANT_ID"
app_id = "CLIENT_ID"
password = "APP_SECRET"

token_endpoint = 'http://login.microsoftonline.com/%s/oauth2/token' % tenant_id
management_uri = 'https://management.core.windows.net/'

payload = { 'grant_type': 'client_credentials',
            'client_id': app_id,
            'client_secret': password
}

auth_response = requests.post(url=token_endpoint, data=payload)
print auth_response.status_code
print auth_response.reason
这将返回:

200
OK
但是,当我打印auth_response.content或auth_response.text时,我会返回一个400 HTML错误代码和一条错误消息

HTTP Error Code: 400
Sorry, but we’re having trouble signing you in. 
We received a bad request.
然而,我能够使用相同的URI和负载,使用PostMan返回正确的信息。我使用Postman中的“Generate Code”选项将请求导出到Python请求脚本,并尝试运行该脚本。但是,我也有同样的错误


有人知道为什么会发生这种情况吗?

您应该使用HTTPS而不是HTTP作为令牌\ U端点,并且还应该指定API版本。这是你应该使用的

token_endpoint = 'https://login.microsoftonline.com/%s/oauth2/token?api-version=1.0' % tenant_id

您应该使用HTTPS而不是HTTP作为令牌_端点,并且还应该指定API版本。这是你应该使用的

token_endpoint = 'https://login.microsoftonline.com/%s/oauth2/token?api-version=1.0' % tenant_id

仅将您的
token\u端点
修改为
https
协议。例如:
token\uhttps://login.microsoftonline.com/%s/oauth2/token“%tenant\u id
。 有关更多详细信息,请参阅


同时,您可以轻松地获取访问令牌。

仅将
令牌\u端点
修改为
https
协议。例如:
token\uhttps://login.microsoftonline.com/%s/oauth2/token“%tenant\u id
。 有关更多详细信息,请参阅

同时,您可以轻松地获得访问令牌