Hi All,
I am new to Python with no cs background. I am trying to export data from RedCap using an API however each time I execute the script it indicates that there is an SSI certificate issue “[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1002)”.
I am using Pycharm in VENV. I’ve try “pip install --upgrade certifi” but still no luck.
Any suggestion or feedback is greatly appreciated!
The below is the script that I use with file path and RedCap URl redacted.
import requests
import pandas as pd
# REDCap API URL and API Token
redcap_api_url = 'https://redcap.xxxx.edu/redcap/api/'
redcap_api_token = 'xxxxx'
# Construct the payload for the exportRecords API method
payload = {
'token': redcap_api_token,
'content': 'record',
'format': 'json',
'type': 'flat', # Specify 'flat' to retrieve all data in a single flat format
}
# Make the request to the exportRecords API method with SSL certificate verification
response = requests.post(redcap_api_url, data=payload, verify=True)
if response.status_code == 200:
exported_data = response.json()
# Convert the data to a pandas DataFrame
df = pd.DataFrame(exported_data)
# Replace spaces in column names with underscores
df.columns = df.columns.str.replace(' ', '_')
# Export DataFrame to Excel
excel_file_path = r'W:\Data\Python_Export\RC_HH_exported_data.xlsx'
df.to_excel(excel_file_path, index=False)
print(f"Data exported to {excel_file_path}")
else:
print(f"Error: {response.status_code}")