Visa Developer Community

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!

3 REPLIES 3
Visa Dev 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

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"}}
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?