Python中的Windows Azure服务管理存在证书问题

Python中的Windows Azure服务管理存在证书问题,python,azure,Python,Azure,我正在使用Ubuntu12.04LTS。 已上载Windows Azure帐户中的.cer文件 我的python脚本是: #!/usr/bin/python from azure import * from azure.servicemanagement import * azureId = "XXXXXXXXXXXXXXXXXXXXX"; certificate_path= "/home/dharampal/Desktop/azure.pem"; sms = ServiceManageme

我正在使用Ubuntu12.04LTS。 已上载Windows Azure帐户中的.cer文件

我的python脚本是:

#!/usr/bin/python
from azure import *
from azure.servicemanagement import *

azureId = "XXXXXXXXXXXXXXXXXXXXX";
certificate_path= "/home/dharampal/Desktop/azure.pem";

sms = ServiceManagementService(azureId,certificate_path)
print sms
result = sms.list_locations()
print result 
当脚本运行时,获取ServiceManagementService对象但引发与证书相关的错误

脚本的输出为:

    <azure.servicemanagement.servicemanagementservice.ServiceManagementService object at 0xb7259f2c>
Traceback (most recent call last):
  File "available_locations_list.py", line 13, in <module>
    result = sms.list_locations()
  File "/usr/local/lib/python2.7/dist-packages/azure/servicemanagement/servicemanagementservice.py", line 796, in list_locations
    Locations)
  File "/usr/local/lib/python2.7/dist-packages/azure/servicemanagement/servicemanagementclient.py", line 96, in _perform_get
    response = self._perform_request(request)
  File "/usr/local/lib/python2.7/dist-packages/azure/servicemanagement/servicemanagementclient.py", line 83, in _perform_request
    resp = self._filter(request)
  File "/usr/local/lib/python2.7/dist-packages/azure/http/httpclient.py", line 144, in perform_request
    self.send_request_headers(connection, request.headers)
  File "/usr/local/lib/python2.7/dist-packages/azure/http/httpclient.py", line 125, in send_request_headers
    connection.endheaders()
  File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 776, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 1161, in connect
    self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file)
  File "/usr/lib/python2.7/ssl.py", line 381, in wrap_socket
    ciphers=ciphers)
  File "/usr/lib/python2.7/ssl.py", line 141, in __init__
    ciphers)
ssl.SSLError: [Errno 336265218] _ssl.c:351: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib
我哪里做错了? 如果有人遇到同样的问题并得到解决,请帮助我。
这正是我在Ubuntu 12.04 LTS上遇到的错误,如果目录或文件名中的证书路径输入错误。因此,请仔细检查您的代码是否正确。

您的代码在我看来很好,所以我不确定您为什么会看到失败,但我可以向您指出创建pem、上载cer并用Python显示一些服务管理代码的方法

它可能更像是您的pem是如何创建的。Python服务管理为我工作,使用以下命令创建pem和cer,然后将相应的cer上载到Windows Azure管理证书存储:

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem -subj "/CN=This Name Shows in the Portal"
openssl x509 -inform pem -in mycert.pem -outform der -out mycert.cer
注意,-subm参数可以方便地控制证书在Windows Azure门户中显示的文本,以便您可以区分它们

还有一个较长的示例,其中几个示例显示了使用Python的示例,包括上面提到的示例