Sharepoint - SharePoint 2013 REST API Request Token: The given key was not present in the dictionary

Question resolved. The error message is completely misleading. It has nothing to do with the token - the problem lies within the strict POST message format SharePoint is requiring. If you use the following headers for your POST request, everything works fine.

headers = {'X-RequestDigest': token,
           'Accept': 'application/json; odata=verbose',
           'Content-Type': 'application/json; odata=verbose',
           'Content-Length': len(json.dumps(payload))}

I came across this error when there was a malformed field in a list. I found it by using the Developer Dashboard and just making the api call from there.

It showed me that there was a lookup list that it could not open, and the lookup field had a render error.

Maybe you are in a similar situation?

Tags:

Rest

List