Asked by:
create filesystem on ADLS Gen2 using rest api python script

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)
- Moved by SumanthMarigowda-MSFTMicrosoft employee, Moderator Wednesday, October 9, 2019 6:50 AM Better suited here
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.
- Proposed as answer by CHEEKATLAPRADEEP-MSFTMicrosoft employee, Moderator Friday, October 11, 2019 8:14 AM
-
-