ValueError: Data must not be a string

1.Just remove the line json_data = json.dumps(data) and change in request as data=data.

2.Remove 'Content-Type': 'application/json' inside headers.

This worked for me.


When you specify your body to a JSON string, you can no longer attach a file since file uploading requires the MIME type multipart/form-data.

You have two options:

  1. Encapsulate your JSON string as part as the form data (something like json => json.dumps(data))
  2. Encode your file in Base64 and transmit it in the JSON request body. This looks like a lot of work though.