Upload Media through WP-Rest API
-
I am trying to upload a pdf document to my media library using the requests library for python. I can’t figure out how I should send the file since I keep getting the following error
b'{"code":"rest_invalid_json","message":"Invalid JSON body passed.","data":{"status":400,"json_error_code":5,"json_error_message":"Malformed UTF-8 characters, possibly incorrectly encoded"}}'
This is how I’m opening the file:
file = open(path, 'rb') r = requests.post(url, headers=headers, data=file)
I have also tried opening the file this way:
file = open(path, 'rb').read()
The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.