Forum Discussion
Anonymous
5 years agoNot applicable
Invalid JSON. A token was not recognized in the JSON content.
I am building a python script for automating add user to datasource, as I debug the script, I am getting this error. full error: {'error': {'code': 'BadRequest', 'message': 'Bad Request', 'detail...
Anonymous
5 years agoNot applicable
HI Anonymous,
I think this should more relate to the 'headers' structure, you can try to use the following codes if it works on your side.
context = adal.AuthenticationContext(authority, validate_authority=True)
token = context.acquire_token_with_username_password(
resource, username, password, clientid
)
accessToken = token["accessToken"]
# print('this is the token:', accessToken) #after this line the code is throwing me the error above.
headers = {
"Authorization": "Bearer " & str(accessToken),
"Content-Type": "application/json",
}
body = {"emailAddress": "[email protected]", "AccessRight": "Read"}
try:
response = requests.post(_uri, headers=headers, data=body)
results = response.json()
print("response:", results)
except Exception as e:
print(str(e))
Regards,
Xiaoxin Sheng