Python中的Azure服务管理 - ssl.SSLError:[SSL] PEM lib(_ssl.c:2084)

时间:2014-08-13 14:57:27

标签: python azure ssl python-3.x

我创建了一个.cer文件并将其上传到Azure管理面板。我使用Administrator:命令提示符创建了这个。

makecert -sky exchange -r -n "CN=AzureCertificate" -pe -a sha1 -len 2048 -ss My "AzureCertificate.cer"

这是我的代码:

from azure import *
from azure.servicemanagement import *

subscription_id = '<MY SUBSCRIPTION ID>'
cert_path = r'C:\AzureCertificate.cer'

sms = ServiceManagementService(subscription_id,cert_path)

result = sms.list_locations()

这是我得到的错误:

Traceback (most recent call last):
  File "<pyshell#37>", line 1, in <module>
    result = sms.list_locations()
  File "C:\Python33\lib\site-packages\azure-0.8.1-py3.3.egg\azure\servicemanagement\servicemanagementservice.py", line 939, in list_locations
    Locations)
  File "C:\Python33\lib\site-packages\azure-0.8.1-py3.3.egg\azure\servicemanagement\servicemanagementclient.py", line 108, in _perform_get
    response = self._perform_request(request)
  File "C:\Python33\lib\site-packages\azure-0.8.1-py3.3.egg\azure\servicemanagement\servicemanagementclient.py", line 95, in _perform_request
    resp = self._filter(request)
  File "C:\Python33\lib\site-packages\azure-0.8.1-py3.3.egg\azure\http\httpclient.py", line 182, in perform_request
    connection = self.get_connection(request)
  File "C:\Python33\lib\site-packages\azure-0.8.1-py3.3.egg\azure\http\httpclient.py", line 143, in get_connection
    host, int(port), cert_file=self.cert_file)
  File "C:\Python33\lib\http\client.py", line 1186, in __init__
    context.load_cert_chain(cert_file, key_file)
ssl.SSLError: [SSL] PEM lib (_ssl.c:2063)

是否有人能够诊断此错误,我在网上找不到太多帮助。

1 个答案:

答案 0 :(得分:1)

您需要将cert_path设置为:     cert_path = 'CURRENT_USER\\my\\AzureCertificate'

http://azure.microsoft.com/en-us/documentation/articles/cloud-services-python-how-to-use-service-management/

按照Mac / Linux&#39;上的管理证书中的说明打开SSL证书。 Windows现在支持上述链接中的部分。它检测是否应该使用httplib或winhttp的方式是cert_path。如果它是文件的路径,它将使用httplib(打开ssl证书)。如果没有,它将使用winhttp。