Skip to content
Advertisement

Converting PHP Curl queries to Python requests

I’ve been facing a few problems trying to convert the following PHP curl queries to Python requests.

Given PHP Code

JavaScript

My version of Python code

JavaScript

Considering my request URLs are the same and so is the base 64 value for authorization. The PHP code returns the right response from the server but the Python one strangely says provides a response telling "code":"UNSUPPORTED_MEDIA_TYPE"

Advertisement

Answer

After some more checks, I seemed to figure out the issue was with the following lines, files needs mandatory filetype which can be obtained from MimeTypes().guess_type(path)[0] and the request_data should have been json.dumps(request_data)

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement