1

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)
c.perform()

I also tried it in requests:

import requests


data = 'action=login&username=user&password=pass'

requests.post('https://localhost:8443', data=data)

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

2 Answers 2

1
import requests


data = {'action': 'login', 'username': 'user', 'password': 'pass'}

requests.post('https://localhost:8443', data=data)
Sign up to request clarification or add additional context in comments.

3 Comments

thanks @Danny and @AyushShanker for your answers! I already tried them before and I keep getting requests.exceptions.SSLError: bad handshake: Error([('SSL routines', 'SSL3_GET_SERVER_CERTIFICATE', 'certificate verify failed')],) any ideas?
well you are using https but in your curl request you used the -k option which according to the curl --help: -k, --insecure Allow connections to SSL sites without certs (H) so in that case to 100% simulate your call you have to add verify=False (like so: requests.post('https://localhost:8443', data=data, verify=False)) to skip the verification of the ssl certificate and not get that error... but then the use of https is kinda pointless.... innit? :)
Thanks Danny it worked, I used data = {'action': 'login', 'username': 'user', 'password': 'pass'} requests.post('https://localhost:8443', data=data, verify=False)
0

here is requests translation

>>> data = 'action=login&username=user&password=pass'
>>> requests.post('https://localhost:8443', data=data)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.