Re: Could not find the TLS certificate file, invalid path - Python Error

maraut
Regular Visitor

Could not find the TLS certificate file, invalid path - Python Error

I have been trying to access Merchant measurement API through Python script and getting this error:

Could not find the TLS certificate file, invalid path:

url = 'https://sandbox.api.visa.com/vdp/....'
headers = { "Accept":"application/json" }
body = {....}
r = requests.get(url,
cert = ( 'PATH/cert.pem' , 'PATH//key.pem' ),
headers = headers) 

 

I tried couple of solutions listed on StackOverflow like manually adding cert files to /lib/site-packages/requests folder etc but nothing seems to be working. Please help!

4 REPLIES 4
jvenkata
Community Moderator

Re: Could not find the TLS certificate file, invalid path - Python Error

Hi,

 

Thanks for reaching out. We are currently looking into this. Will get back to you shortly.


Thanks,

Jai

maraut
Regular Visitor

Re: Could not find the TLS certificate file, invalid path - Python Error

This is my complete script:

 

import requests
import json

def fetch_merchant_measurement_data():

headers = {
'Accept': 'application/json',
'Authorization':'b64 endoded username:password'
}
payload = {

"requestHeader":{
"messageDateTime":"2019-03-01T22:09:39.327Z",
"requestMessageId":"6da60e1b8b024532a2e0eacb1af58581"
},
"requestData":{
"naicsCodeList":[
""
],
"merchantCategoryCodeList":[
"5812"
],
"merchantCategoryGroupsCodeList":[
""
],
"postalCodeList":[
""
],
"msaList":[
"7362"
],
"countrySubdivisionList":[
""
],
"merchantCountry":"840",
"monthList":[
"201706"
],
"accountFundingSourceList":[
"ALl"
],
"eciIndicatorList":[
"All"
],
"platformIDList":[
"All"
],
"posEntryModeList":[
"All"
],
"cardPresentIndicator":"CARDPRESENT",
"groupList":[
"STANDARD",
"CARDHOLDER",
"CBREASONCODE"
]
}

}
url = "https://sandbox.api.visa.com/merchantmeasurement/v1/merchantbenchmark"

response = requests.post(url,
verify = ('/path/rootCACerti.pem'),
cert=('/path/cert.pem', '/path/privateKey.pem'),
headers = headers,
auth = ('username', 'password'),
data = json.dumps(payload))
response.raise_for_status()
print(response.text)
return response.json()

response = fetch_merchant_measurement_data()

 

I am getting this error now:

{"error":{"code":"CDI001","message":"Bad Request"}}
alaneng
Helper

Re: Could not find the TLS certificate file, invalid path - Python Error

Hey maraut, I ended up in the same position as you with the "Bad Request" error (while also getting response code 200). Do you recall what you ended up doing?
Antoniio
Occasional Visitor

Re: Could not find the TLS certificate file, invalid path - Python Error

I ran into this problem as well. It looks like it comes from the certificate bundle cacert.pem not being included in the requests package directory when the program is compiled. The requests module uses the function certifi.core.where to determine the location of cacert