API call works in RapidAPI playground but fails with SSL errors in local development environment

I’m pretty new to working with APIs and running into a frustrating issue. I’m trying to use a flight search API from RapidAPI in my Python project. When I test the API call directly in RapidAPI’s browser interface, everything works perfectly and I get the expected results.

But when I copy the exact same code into my local Python environment, I keep getting SSL certificate errors. The main error message says “certificate verify failed: unable to get local issuer certificate”.

Here’s the code I’m using:

import requests

api_url = "https://flightapi55.p.rapidapi.com/flights"

params = {
    "passengers": "2",
    "from": "NYC",
    "to": "MIA", 
    "departure": "2023-12-20",
    "return": "2023-12-27",
    "class": "business",
    "currency": "EUR"
}

request_headers = {
    "X-RapidAPI-Key": "my-api-key-here",
    "X-RapidAPI-Host": "flightapi55.p.rapidapi.com"
}

api_response = requests.get(api_url, headers=request_headers, params=params)
print(api_response.json())

I’m using Anaconda and Python 3.9. Has anyone else run into this SSL verification problem when moving from RapidAPI’s test environment to local development? What’s the best way to fix this?

Had this exact problem last month with a different RapidAPI endpoint. Your local Python environment probably doesn’t trust RapidAPI’s certificate chain. Are you behind a corporate firewall or using a VPN? Those usually intercept SSL connections and break verification. If updating certificates doesn’t help, you can add verify=False to your requests.get() call for testing - but don’t use this in production. The real fix is installing whatever intermediate certificates your network needs. Also check your system clock since SSL certificates are time-sensitive.

same ssl headache here! update your certificates first - run conda update ca-certificates then restart your terminal. still broken? try pip install --upgrade certifi - usually fixes those annoying cert errors. good luck!

This SSL issue usually means Python’s certificate store is outdated or missing intermediate certificates. Since you’re using Anaconda, try conda install certifi then conda update certifi to refresh the certificate bundle. Your Python installation might not be finding the right CA bundle location either. Check this by adding import ssl; print(ssl.get_default_verify_paths()) to see where Python’s looking for certificates. If those paths look wrong, set the REQUESTS_CA_BUNDLE environment variable to point to your certifi bundle - that usually fixes it. Since RapidAPI’s playground works, their servers are fine. This is definitely a local certificate validation problem.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.