1

I am trying to make REST Call for azure using python, Have created Access token using ADAL in python. But getting Error called "provided Authorization header is in invalid format." Here is the code for that:

    import adal
    import requests

    token_response = adal.acquire_token_with_username_password(
    'https://login.windows.net/abcd.onmicrosoft.com',
    'user-name',
    'password'
    )

    access_token = token_response.get('accessToken')

    url = 'https://management.azure.com/subscriptions/{subscription-    id}/providers/Microsoft.Network/virtualnetworks?api-version=2015-06-15'
    headers = {'Content-Type': 'application/json',
          'Authorization': access_token}

    response = requests.get(url=url,headers = headers)
    print(response.status_code)
    print(response.text)

Can anyone tell me how the access-token should look like? And is this the correct way to generate token for REST in python? I am reffering this link for above code: https://msdn.microsoft.com/en-us/library/azure/mt163557.aspx

2 Answers 2

1

As @GauravMantri said, the format of the value of the header Authorization is Bearer <access-token> that you can refer to the section Calling ARM REST APIs of the doc "Resource Manager REST APIs".

For example in the section above.

GET /subscriptions/SUBSCRIPTION_ID/resourcegroups?api-version=2015-01-01 HTTP/1.1
Host: management.azure.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Content-Type: application/json

Sign up to request clarification or add additional context in comments.

Comments

0

You would need to prepend Bearer to your token. Something like:

headers = {'Content-Type': 'application/json',
          'Authorization': 'Bearer ' + access_token}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.