So I'm trying to use python requests to make a PUT request to Azure (to create/update notification hub - https://learn.microsoft.com/en-us/rest/api/notificationhubs/notificationhubs/createorupdate#mpnscredential .
My code:
url = "https://management.azure.com/subscriptions/mysub/resourceGroups/Default-NotificationHubs-WestEurope/providers/Microsoft.NotificationHubs/namespaces/myNamespace/notificationHubs/notificationHubName?api-version=2016-03-01"
bearer_token = "my very long token"
headers = {
"dataType": "json",
"accept":"application/json",
"contentType":"application/json",
"Authorization": "Bearer " + bearer_token }
filepath = "/Users/..../pathTo.p12"
with open(filepath) as fh:
byte_array_p12 = fh.read()
data = {
'location': "West Europe",
'properties.apnsCredential': {
'properties.apnsCertificate': byte_array_p12,
'properties.certificateKey': "some nice pass"
}
}
r = requests.put(url, data, headers = headers)
But running r gives me 415 error.
r.text
u'{"error":{"code":"UnsupportedMediaType","message":"The content media type \'application/x-www-form-urlencoded\' is not supported. Only \'application/json\' is supported."}}'
Where did that \'application/x-www-form-urlencoded\'
come from?
I am explicitly setting headers for that request, and that one is not included... I am clueless.
I have tried the "Try" functionality on the afformentioned Azure page, where you can try constructing the body yourself, but it is buggy...
Thanks for any help!