How to I use this certificate in requests.post ? #18
ashupednekar
started this conversation in
General
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 |
0 replies
|
@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.nameUse: 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 |
0 replies
|
Hello, |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment


Uh oh!
There was an error while loading. Please reload this page.
All reactions