将Azure服务管理与python sdk连接

将Azure服务管理与python sdk连接,python,python-2.7,azure,sdk,azure-service-fabric,Python,Python 2.7,Azure,Sdk,Azure Service Fabric,我正在使用此指南: . 我正在做他们在指南中写的事情,我不断收到错误信息 >>> from azure import * >>> from azure.servicemanagement import * >>> subscription_id = '************************' >>> import os >>> os.path.isfile(r'c:\key\mycert.pem'

我正在使用此指南: . 我正在做他们在指南中写的事情,我不断收到错误信息

>>> 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文件正常。

根据您的错误信息和的官方文件,问题原因如错误信息所述,如下所示

根据我的经验,我认为有两个原因会导致这个问题

  • 您当前使用的证书在Azure上无效。除了重新生成引用到office的新证书外,您还可以按照Azure SDK for Python的文档创建客户机证书
  • 使用Azure.PublishSettings证书

    您可以下载Azure发布设置文件,并使用该文件中嵌入的证书创建客户端证书。服务器证书已经存在,因此您不需要上载证书

  • 服务器证书文件未上载到Azure管理门户设置,如下所示
  • 作为参考,这里有一篇由@GauravMantri编写的文章,对您非常有帮助,它详细介绍了Java的各个步骤


    希望能有所帮助。

    我看到的403错误和服务管理API的一个常见原因是,像Fiddler这样的工具正在运行。你能不能检查一下情况是否如此。有什么更新或问题吗?