Problems updating lesson content using python

Dear Developers,
I try to update/modify the content of my lessons using the “request” library of python. Some of the fields like “level” or ‘originalUrl’ are “null” when I check the lesson details using the GET statement. When I try to send the exact same data back using the PUT statement it fails. The server seems to process the data, but it seems not to be happy about the content of the “null” value. The server respond is: u’originalUrl’: [u’This field may not be null.‘]. I tried to send an empty string, answer: [u’This field may not be blank.’]. I removed the entry from the dictionary, answer: [u’This field is required.'].

The call looks like this: resp = requests.put(‘https://www.lingq.com/api/v2/ru/lessons/(ContentID)/’, json=data, headers={‘Authorization’: 'Token ’ + API_KEY})

data={“title”: “08150815”, “originalUrl”: null, … , “price”: 0}

What can I do to convince the server to keep some entry without any value e.g. “null”?

Thanks

An entry without any value this is “null”. If you don’t want to specify some value it becomes undefined which is “null” in JSON/JavaScript or “None” in python. I would suggest you to use PATCH instead of PUT and update only entries you need.

1 Like

Thanks a lot for the answer. I guess I go for the PATCH. I used requests.patch… (the rest like above) and data={“text”:“…”}, but the text was not updated. The server response was anyway 200. Is there something wrong with my dictionary? What is the correct key name for updating the text using the patch method for the single lesson?