API endpoint works in online testing environment but fails with SSL errors in local development setup

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 everything in the RapidAPI browser interface, the API calls work perfectly fine and return the expected data.

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_city": "NYC", 
    "to_city": "MIA",
    "depart_date": "2023-09-15",
    "return_date": "2023-09-22",
    "class_type": "business",
    "currency_code": "USD"
}

request_headers = {
    "X-RapidAPI-Key": "YOUR_API_KEY_HERE",
    "X-RapidAPI-Host": "flightapi55.p.rapidapi.com"
}

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

The error traceback shows it’s failing during the SSL handshake process. Has anyone else run into this kind of issue where APIs work in browser testing but not locally? What could be causing this difference in behavior?

had this exact headache with rapid api last month! usually it’s ur local machine’s ssl setup vs the browser’s. quick fix that worked for me - downgrade ssl verification or check if ur system time’s correct. messed up system clock can cause cert validation failures. also try pip install --upgrade requests urllib3 since older versions sometimes choke on newer ssl certs.

This SSL issue pops up all the time when you move from browser testing to local development. RapidAPI’s online environment handles SSL verification differently than your local Python setup. I hit this exact problem last year with external APIs. Your machine’s probably missing intermediate certificates or using old certificate bundles. Try updating your Python certificates first: pip install --upgrade certifi - this updates the certificate bundle that requests uses. If that doesn’t work, you can temporarily add verify=False to your requests call, but don’t do this in production. Better option: specify the certificate bundle explicitly with verify=certifi.where() after importing certifi. Updating Python itself also worked for me since newer versions include more recent certificate authorities. Browser testing works because browsers keep their own certificate stores, which are usually more current than Python’s default bundle.