Send curl POST Request in Python without installing a lib

Viewed 160

I wanna send a curl post request in python. But I can't install any lib like 'request'. I could send POST request like following example :

curl -H "Content-Type: application/json" -X POST -d {\"username\":\"myusername\",\"password\":\"mypassword\"} https://example.com/login

I need equal code as the above in python2. Then, i must read what it returns. I'm working on Windows 10.

1 Answers

Write a curl command in a way that it can work in the shell and then execute the command in the shell. This way you don't need the requests package.

import os
command = "curl -u {username}:{password} [URL]"
os.system(command)
Related