Reputation: 2077
I need to convert a curl statement to Python
curl -k -d 'id=id1' --data-urlencode 'username=user1' --data-urlencode 'password=pass1' https://aaaa.bbb.com:nnnn
I was able to use
import requests
data = [
('id', 'id1'),
]
response = requests.post('https://aaaa.bbb.com/:nnnn', data=data)
With this I get certificate_verify_failed. How can I include urlencode for the username and password
Upvotes: 1
Views: 1528
Reputation: 1062
The reason for certificate_verify_failed
is perhaps because the client is trying to verify the server certificate and failing in doing so. You may disable the verification on the client side by using verify=False
import requests
url = "https://aaaa.bbb.com:nnnn"
headers = {}
data = {
"id": "id1"
}
response = requests.post(url, data=data, headers=headers, verify=False)
Upvotes: 1
Reputation: 1084
For bypassing certification check use (verify=False) :
response = requests.post('https://aaaa.bbb.com/:nnnn', data=data, verify=False)
and for ensuring to send data as url encoded :
response = requests.post('https://aaaa.bbb.com/:nnnn', data=data, verify=False, headers={'Content-Type':'application/x-www-form-urlencoded'})
Upvotes: 6