How to I use this certificate in requests.post ? #18
Replies: 3 comments
-
what do I do with the _cert object? Please provide some example use-cases, like using the certs in an api call |
Beta Was this translation helpful? Give feedback.
-
@ashupednekar, I will implement something using the same class as this project. from contextlib import contextmanager
from tempfile import NamedTemporaryFile
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, NoEncryption
from cryptography.hazmat.primitives.serialization.pkcs12 import load_key_and_certificates
@contextmanager
def pfx_to_pem(pfx_path, pfx_password):
pfx = open(pfx_path, 'rb').read()
private_key, main_cert, add_certs = load_key_and_certificates(pfx, pfx_password.encode('utf-8'), None)
with NamedTemporaryFile(suffix='.pem') as t_pem:
with open(t_pem.name, 'wb') as pem_file:
pem_file.write(private_key.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption()))
pem_file.write(main_cert.public_bytes(Encoding.PEM))
for ca in add_certs:
pem_file.write(ca.public_bytes(Encoding.PEM))
yield t_pem.name Use: with pfx_to_pem(pfx_file_path, pfx_password) as cert:
response = requests.get(
url=url,
headers=headers,
cert=cert,
verify=True
)
return response.text |
Beta Was this translation helpful? Give feedback.
-
Hello, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions