How To Use .p12 Certificate To Authenticate Rest Api
I have received a certificate.p12 with username and password. While I am able to use Rest Client for post requests after i install this certificate in my system. How can i use this
Solution 1:
Ref: https://github.com/m-click/requests_pkcs12
I was using payload
data={"folder": "/Trial/trial_dir"}
which is a dictionary while it should be a proper string of dictionary
data='{"folder": "/Trial/trial_dir"}'
So the following are the findings for successful post requests with python :-
- Header parameter should be a dictionary.
e.g.
headers={'Content-Type': 'application/json'}
- Data parameter should be a dictionary in string format.
e.g.
data='{"folder": "/Trial/trial_dir"}'
- Verify should be set to False :
verify=False
as to ignore verifying the SSL certificate.
Below is the status and contents received from request I made:
>>>import json>>>from requests_pkcs12 import get,post>>>url = 'https://IP:8080/siteapi/availabletests'>>>pkcs12_filename = 'C:\\Users\\ukhare\\Desktop\\tests\\trial_tata.p12'>>>pkcs12_password = 'trialtest'>>>response = post(url, data='{"folder": "/Trial/trial_dir"}', headers={'Content-Type': 'application/json'}, verify=False, pkcs12_filename=pkcs12_filename,pkcs12_password=pkcs12_password)
D:\m\Python34\lib\site-packages\urllib3\connectionpool.py:857: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
>>>print(response.status_code)
200
>>>print(json.dumps(json.loads(response.content.decode("utf-8")), indent=4, separators=(',', ': '), sort_keys=True))
{
"availableTests": [
"/Trial/trial_test/HTTP_Download"
],
"serviceError": null
Post a Comment for "How To Use .p12 Certificate To Authenticate Rest Api"