我正在使用本指南: https://learn.microsoft.com/en-us/azure/cloud-services/cloud-services-python-how-to-use-service-management 。 我正在按照他们在指南中所写的方式进行操作,但我不断收到错误消息。
>>> from azure import *
>>> from azure.servicemanagement import *
>>> subscription_id = '************************'
>>> import os
>>> os.path.isfile(r'c:\key\mycert.pem')
True
>>> certificate_path = r'c:\key\mycert.pem'
>>> sms = ServiceManagementService(subscription_id, certificate_path)
>>> result = sms.list_locations()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\python27\lib\site-packages\azure\servicemanagement\servicemanagementservice.py", line 1131, in list_locations
Locations)
File "C:\python27\lib\site-packages\azure\servicemanagement\servicemanagementclient.py", line 365, in _perform_get
response = self.perform_get(path, x_ms_version)
File "C:\python27\lib\site-packages\azure\servicemanagement\servicemanagementclient.py", line 175, in perform_get
response = self._perform_request(request)
File "C:\python27\lib\site-packages\azure\servicemanagement\servicemanagementclient.py", line 339, in _perform_request
return _management_error_handler(ex)
File "C:\python27\lib\site-packages\azure\servicemanagement\servicemanagementclient.py", line 419, in _management_error_handler
return _general_error_handler(http_error)
File "C:\python27\lib\site-packages\azure\servicemanagement\_common_error.py", line 34, in _general_error_handler
raise AzureHttpError(message, http_error.status)
azure.common.AzureHttpError: Forbidden
<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>ForbiddenError</Code><Message>The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.</Message></Error>
我已将 mycert.cer 上传到我的 Azure 门户中的云服务。 有人知道问题出在哪里吗? 我确定 pem 和 cer 文件没问题。
最佳答案
根据您的错误信息以及Service Management Status and Error Codes
的官方文档,问题原因如下错误信息所述。
根据我的经验,我认为有两个原因会导致此问题。
- 您当前使用的证书在 Azure 上无效。另外重新生成新证书引用官方document ,您也可以按照Azure SDK for Python的文档
Using the Azure .PublishSettings certificate
创建客户端证书。
Using the Azure .PublishSettings certificate
You can download your Azure publish settings file and use the certificate that is embedded in that file to create the client certificate. The server certificate already exists, so you won’t need to upload one.
- 服务器证书文件未上传到 Azure 管理门户设置中,如下所示。
作为引用,有一个 blog @GauravMantri 写的,对你很有帮助,虽然是针对 Java 的,但它详细介绍了步骤。
希望有帮助。
关于python - 将 Azure 服务管理与 python sdk 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42981804/