kennethreitz/requests — Issue #226: How do I use PATCH with an external json file?
Author: tlam
Created: 2011-10-25 20:18:05+00:00
State: open

I'm currently trying to translate the example given at http://www.salesforce.com/us/developer/docs/api_rest/Content/dome_update_fields.htm into requests.

The corresponding PATCH action is:

curl https://na1.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe -H "Authorization: OAuth token" -H "X-PrettyPrint:1" -H "Content-Type: application/json" -d @patchaccount.json -X PATCH

With json:

{
"BillingCity" : "San Francisco"
}

My current code looks like:

import requests

data = {'BillingCity': 'San Francisco'}
url = 'https://na1.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe'
headers = {
'Authorization': 'OAuth token',
'Content-Type': 'application/json',
}
r = requests.patch(url, headers=headers, data=data)

Apparently, I'm missing something from the above. Is there a way to use PATCH in requests without writing the json content in an external file?