I’m pretty new to working with APIs and running into a weird issue. I’m trying to use a flight search API, which works perfectly when I test it directly on the API provider’s website. However, when I run the exact same code in my local development environment, I get SSL certificate errors.
Here’s my code:
import requests
api_url = "https://flightapi12.p.rapidapi.com/flights"
parameters = {
"passengers": "2",
"from": "JFK",
"to": "SFO",
"departure": "2023-09-15",
"return": "2023-09-22",
"class": "business",
"currency": "EUR"
}
request_headers = {
"X-RapidAPI-Key": "YOUR_API_KEY_HERE",
"X-RapidAPI-Host": "flightapi12.p.rapidapi.com"
}
api_response = requests.get(api_url, headers=request_headers, params=parameters)
print(api_response.text)
The error I’m getting is:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
Why would this work in the browser testing environment but not locally? Is there something I need to configure in my Python setup?
This usually happens because your Python environment has old certificate bundles or there’s corporate firewall interference. Browsers use the system’s certificate store, but Python requests uses its own certificates through the certifi package. First, try updating your certificates with pip install --upgrade certifi requests
. If that doesn’t work, you’re probably behind a corporate proxy that’s intercepting SSL connections. I ran into the same thing at my office - IT had to give me specific certificate files to trust their proxy. Your Python installation might also need updating since older versions sometimes can’t verify certificates with newer APIs.
yeah, sounds like your local setup’s missing the right certificates. quick fix: add verify=False
to your requests. just don’t use that in production - it’ll skip all cert checks.
Had this exact problem switching from Postman to local implementation. Your Python environment probably doesn’t trust the API’s certificate chain. First thing I’d check - is your company using a proxy? Our IT was intercepting HTTPS traffic and swapping certificates. Try running your code from home wifi. If it works there, it’s definitely network-related. Also check your system clock - I wasted hours on SSL errors once because my laptop time was wrong and certificates looked expired. Before you disable SSL verification, run the same request with curl from command line. You’ll get better error details about what’s actually failing in the certificate validation.