Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python code for sending requests with certificate, private encrypted key and password

Tags:

python

urllib3

I'm trying to fetch response from an https call which has certificate installed atits side. This is my code

import requests
import urllib3

urllib3.disable_warnings()

cert_file_path = "/path/output-crt-file-name.crt"
key_file_path = "/path/output-key-file-name.key"
passwd = 'secretpass'
print(passwd)
url = "https://url/to/fetch/response"
params = {"AppID": "xxxx", "Safe": "xxxx", "Folder": "Root",
          "Object": "xxxx"}
cert = (cert_file_path, key_file_path, passwd)
r = requests.get(url, params=params, cert=cert, verify=True )
print(r.text)

which throws error

Caused by SSLError('Client private key is encrypted, password is required'

Please suggest.

like image 500
bosari Avatar asked Sep 09 '25 14:09

bosari


1 Answers

I'm afraid requests doesn't currently support using encrypted private key, see https://2.python-requests.org/en/master/user/advanced/#client-side-certificates:

The private key to your local certificate must be unencrypted. Currently, Requests does not support using encrypted keys.

See https://security.stackexchange.com/questions/59136/can-i-add-a-password-to-an-existing-private-key for instructions how to remove your key's encryption.

like image 90
Michael Yakobi Avatar answered Sep 12 '25 03:09

Michael Yakobi