0

I am having some issue with my Azure AD password reset code that am not able to fix and I need some help around literals and strings.

myVar = ad.getAuthToken('18f96976-a-d-d7f1-wontwork-3c0c86a2','donttry-d-dOYqojM[O03vaRaEr/S.=')
print(myVar)

url = 'https://graph.microsoft.com/v1.0/users/'+  str(u_portal_id) + '@someaccount.net'


payload = '{ "passwordProfile" : {"forceChangePasswordNextSignIn": "False","password": "' + 
newPassword +'"}}'

headers = '{"content-type": "application/json", "authorization":"' + myVar +'"}'

print(payload)
print(headers)
print(url)
response = requests.request("PATCH", url, data=json.dumps(payload), headers=headers)

When I print the values for payload, header and url, I get the following:-

PAYLOAD = { "passwordProfile" : {"forceChangePasswordNextSignIn": "False","password": "MZSbvxe$6136"}}

HEADERS= {"content-type": "application/json", "authorization":"Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI6ImxFY19DTU1FWnRjZWJpbF9oTExQbDNJVDZockNGMjdnSmJRU3FrSUdSdUEiLCJhbGciOiJSUzI1NiIsIng1dCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSIsImtpZCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSJ9.eyJhdWQiOiJodHRwczovL2dyYXBoLm1pY3Jvc29mdC5jb20iLCJpc3MiOiJodHRwczovL3N0cy53aW5kb3dzLm5ldC8zM2YxZWFmMC00MGI2LTRmNWItYmFmMC0wNGRlZTljMzM5YTgvIiwiaWF0IjoxNTc5Njg3ODY5LCJuYmYiOjE1Nzk2ODc4NjksImV4cCI6MTU3OTY5MTc2OSwiYWlvIjoiNDJOZ1lKaWwxbWx0Zmtuc3dNNkwzTjkvL2ovZkFBQT0iLCJhcHBfZGlzcGxheW5hbWUiOiJJbnR1bmVNU0JPVCIsImFwcGlkIjoiMThmOTY5NzYtYWRjZS00N2YxLWFmODYtM2NlYzg5MGM4NmEyIiwiYXBwaWRhY3IiOiIxIiwiaWRwIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvMzNmMWVhZjAtNDBiNi00ZjViLWJhZjAtMDRkZWU5YzMzOWE4LyIsIm9pZCI6IjEwYmYxNTk1LTA5MzgtNDNkNi05MzU3LTIxYTJjOGNlMWQxMCIsInJvbGVzIjpbIkRldmljZU1hbmFnZW1lbnRTZXJ2aWNlQ29uZmlnLlJlYWRXcml0ZS5BbGwiLCJEZXZpY2VNYW5hZ2VtZW50TWFuYWdlZERldmljZXMuUmVhZFdyaXRlLkFsbCIsIkRldmljZU1hbmFnZW1lbnRDb25maWd1cmF0aW9uLlJlYWRXcml0ZS5BbGwiLCJEZXZpY2VNYW5hZ2VtZW50QXBwcy5SZWFkV3JpdGUuQWxsIiwiRGV2aWNlTWFuYWdlbWVudFJCQUMuUmVhZFdyaXRlLkFsbCJdLCJzdWIiOiIxMGJmMTU5NS0wOTM4LTQzZDYtOTM1Ny0yMWEyYzhjZTFkMTAiLCJ0aWQiOiIzM2YxZWFmMC00MGI2LTRmNWItYmFmMC0wNGRlZTljMzM5YTgiLCJ1dGkiOiIycXdKOHp6bDcwMmRfYndGYkZVVEFBIiwidmVyIjoiMS4wIiwieG1zX3RjZHQiOjE1MzYxNTIxNDZ9.e0f4OYAWIwvHit2XT_8fneGVzIbwGORKabgCUFf2nBkfBBFys2S0Xibpx3r47wPARXt5qZyRrAAWu18mpfRnxY1DdXvtdDiZmHRY9ZJfmRB_2HOLfJKTyJUjYUkMESlozQzVDBj9-dontryitwontwork-dNUgOALUyXk--DiZsm8WTN9exnbGoQnfz5TyWWnTm3H9udyLEIkUMfG8NjBO190b7ZNARnLcT2EHremOL2M8OFcLIGAUJoVyukVxa_rEN37b_hqb7l_tx7sVcuf1zM1D7s66L6Nre1Db7OZZdUDdvOWD4vJzauEe9niFFfrefRet8EwvJQ"}

URL = https://graph.microsoft.com/v1.0/users/124708@someaccount.net

I have verified it via JSON Parser to be correct. Also Postman doesn't throw any error. Kindly assist.

The error that I am getting is the following:-

'str' object has no attribute 'items'

Community
  • 1
  • 1
Sash Sheen
  • 105
  • 2
  • 14
  • 1
    You are passing in a string; headers can't ever be a JSON encoded string, it is always a Python dictionary. See https://stackoverflow.com/questions/18867898/attributeerror-str-object-has-no-attribute-items?rq=1. – Allen Wu Jan 23 '20 at 03:07
  • Thank you @AllenWu ! I figured it out later. – Sash Sheen Jan 23 '20 at 10:50
  • It looks like your problem is solved. I sorted out the solution. If it helps, please accept it as the answer. Thank you. – Allen Wu Jan 24 '20 at 01:09

2 Answers2

0

You are passing in a string; headers can't ever be a JSON encoded string, it is always a Python dictionary.

Check your code carefully and correct it.

Allen Wu
  • 15,529
  • 1
  • 9
  • 20
0

Here is how I solved it

    payload = {
        "passwordProfile" : {
            "forceChangePasswordNextSignIn": False,
            "password": newPassword
        }
    }

    headers = {"content-type": "application/json", "authorization": myVar }
    response = requests.request("PATCH", url, data=json.dumps(payload), headers=headers)
Sash Sheen
  • 105
  • 2
  • 14