PATCH update request from python requests library won't work

I am trying to update a record’s attachments field.

I am doing this successfully with curl, and also I have python code that successfully pulls records from the table; however when I add code to that which tries the PATCH, I get a “Could not parse request body” 422 response.

Below is the code.


import requests
import datetime
import json

hed = {‘Authorization’: 'Bearer ’ + auth_token, ‘Content-Type’: ‘application/json’}

url = ‘

print(“GET’ing records…”)

response = requests.get(url, headers=hed)

r2 = { ‘fields’: { ‘mytext’: ‘success’}}

print(“PATCH request…”)

# THIS REQUEST FAILS WITH 'Could not parse request body’
presp = requests.patch(url, headers=hed, data=r2)
print(presp.text, presp)

Found the solution: requests.patch(url, headers=hed, json=r2)

This topic was solved and automatically closed 15 days after the last reply. New replies are no longer allowed.