Support » Developing with WordPress » Upload Media through WP-Rest API

  • Resolved ascuadrado

    (@ascuadrado)


    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()

    • This topic was modified 1 month ago by ascuadrado.
    • This topic was modified 1 month ago by ascuadrado.

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • ascuadrado

    (@ascuadrado)

    There was a typo in my header that gave me problems with the encoding-decoding of the data. It’s solved!

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.