[英]Python HTTPS against Azure service management API fails on Windows
[英]Creating a Windows Azure Service through the REST API on Python
我正在嘗試使用REST API和Python在Windows Azure上創建服務。 代碼如下:
def create_service(self):
subscription_id = self.get_user_subscription_id()
auth = self.get_user_cert_data()
if auth is None or subscription_id is None:
return [(False, "Datos de autenticacion incorrectos")]
else:
key_file, cert_file = auth
service_name = str(int(time.time()*100))
try:
conn = httplib.HTTPSConnection(self.AZURE_SERVER, self.AZURE_PORT, key_file=key_file, cert_file=cert_file)
uri = "https://%s/%s/services/hostedservices" % (self.AZURE_SERVER,subscription_id)
service_create_xml = '''
<CreateHostedService xmlns="http://schemas.microsoft.com/windowsazure">
<ServiceName>%s</ServiceName>
<Label>%s</Label>
<Description>Service %s created by the IM</Description>
<Location>West Europe</Location>
</CreateHostedService>
''' % (service_name, base64.b64encode(service_name), service_name )
conn.request('POST', uri, body = service_create_xml, headers = {'x-ms-version' : '2013-03-01', 'ContentType' : 'application/xml'})
resp = conn.getresponse()
except Exception, ex:
self.logger.exception("Error creando el service")
return None
if resp.status != 201:
self.logger.error("Error creando el service: Codigo " + str(resp.status) + " Reason: " + str(resp.reason))
return None
return service_name
但是,由於某些未知原因,響應始終是錯誤400錯誤請求。 有人知道我在做什么錯嗎? 提前致謝。
對於此處的標題:
標頭= {'x-ms-version':'2013-03-01',' ContentType ':'application / xml'}
嘗試使用Content-Type
而不是ContentType
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.