tkyass tkyass - 1 year ago 136
Python Question

Transforming curl command into Python pycurl or requests

Trying to use this curl command, in Python:

curl -k -X POST --data "action=login&username=user&password=pass" https://localhost:8443

I already tried using pycurl as the following:

import pycurl
c = pycurl.Curl()
c.setopt(pycurl.URL, "https://localhost:8443")
c.setopt(pycurl.POST, 1)
#tried this too
#c.setopt(pycurl.USERPWD, 'user:pass')
c.setopt(c.HTTPHEADER,"action=login&username=user&password=pass" )
c.setopt(c.VERBOSE, True)

I also tried it in requests:

import requests

data = 'action=login&username=user&password=pass''https://localhost:8443', data=data)

but it didn't work. Don't know what I'm missing, any suggestions?

Answer Source
import requests

data = {'action': 'login', 'username': 'user', 'password': 'pass'}'https://localhost:8443', data=data)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download