none
create filesystem on ADLS Gen2 using rest api python script RRS feed

  • Question

  • after running the following code i am getting this error:

    "error":{"code":"AuthenticationFailed","message":"Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature

    import requests
    import RestResponse

    spn_id='' #spn id
    fs_name=''#fsname
    spn_val=''#spn_passsword



    def create_adls_gen2_fs(spn_id, spn_val, fs_name):


        try:
            tenant_id ='value of tenant'

            header1 = {

                'Content-Type': 'application/x-www-form-urlencoded'
            }

            data = {

            "client_id": spn_id,

            "client_secret": spn_val,

            "scope" : "https://storage.azure.com/.default",

            "grant_type" : "client_credentials"
            }

            response = requests.post('https://login.microsoftonline.com/tenant_id/oauth2/token', data=data,headers=header1)
            print(response)
            var2 = RestResponse.parse(response.json())

            print(var2)



            access_token = var2.access_token

            header2 = {

            'Content-Length' : '0',

            'x-ms-version': '2018-11-09',

            'Authorization' : 'Bearer' +access_token
           }

            url = "https://adlsneg2.dfs.core.windows.net/mydata?resource=filesystem"
            #querystring = {"resource":"filesystem"}
            response = requests.request("PUT", url, headers=header2)
            print(response)
            print(response.content)

        except Exception as e:
            raise Exception('Error Occured: {}'.format(e))
            print("Error while creating a File System")

        return response.text

    create_adls_gen2_fs(spn_id, spn_val, fs_name)

                                                                                    
    Wednesday, October 9, 2019 5:57 AM

All replies

  • Hi gautam_nanda,

    This error occurs if the service principal you are using for Azure Data Lake Storage Gen2 is not granted the appropriate role assignment. 

    For more details, you may refer MSDN thread which addressing similar issue.

    Hope this helps.      

    ----------------------------------------------------------------------------------------

    Do click on "Mark as Answer" and Upvote on the post that helps you, this can be beneficial to other community members.

    Friday, October 11, 2019 8:14 AM
    Moderator
  • Hi Gautam_nanda,

    Just checking in to see if the above answer helped. If this answers your query, do click “Mark as Answer” and Up-Vote for the same. And, if you have any further query do let us know.

    Monday, October 14, 2019 8:26 AM
    Moderator
  • Hi Gautam_nanda,

    Following up to see if the above suggestion was helpful. And, if you have any further query do let us know.

    Tuesday, November 5, 2019 6:30 AM
    Moderator