Hey guys, I’m new to using APIs and I’m stuck. I’m trying to use the Skyscanner API from RapidAPI for a project. It works fine when I test it in the RapidAPI playground, but when I copy the same code to my local setup, it’s giving me a headache.
Here’s a simplified version of what I’m trying:
import requests
url = "https://flightfinder.example.com/search"
params = {
"passengers": "2",
"from": "JFK",
"to": "SFO",
"leave": "2023-12-01",
"return": "2023-12-10",
"class": "business",
"money": "EUR"
}
headers = {
"API-Key": "your-api-key-here",
"API-Host": "flightfinder.example.com"
}
result = requests.get(url, headers=headers, params=params)
print(result.text)
But when I run this, I get a bunch of errors. The main one is something about a “certificate verify failed” error. It’s really frustrating! Any insights on what might be causing this or how I can resolve it? Thanks in advance for any help!
yo henryg, sounds like a SSL cert issue. try adding verify=False
to ur requests.get() call. like this:
result = requests.get(url, headers=headers, params=params, verify=False)
but heads up, this kinda disables security checks. maybe check if ur using latest python/requests versions too. good luck man!
I’ve encountered similar issues before. The ‘certificate verify failed’ error often stems from your local environment not having the necessary SSL certificates. Instead of disabling verification, which can be risky, try updating your certifi package:
pip install --upgrade certifi
If that doesn’t work, check your system’s certificate store. On Windows, ensure you’re using the latest version of the requests library, as older versions had issues with the Windows certificate store.
Another approach is to specify the certificate path explicitly:
import certifi
result = requests.get(url, headers=headers, params=params, verify=certifi.where())
This should resolve the SSL issue while maintaining security. Let me know if you need further assistance.
Hey henryg, I feel your pain! I went through something similar when I first started working with APIs. It sounds like you’re dealing with a classic SSL certificate issue. Here’s what worked for me:
First, try updating your certifi package as charlottew suggested. If that doesn’t do the trick, you might want to check your Python installation. Sometimes, Python doesn’t play nice with the system’s SSL certificates.
Another thing that helped me was explicitly setting the SSL context:
import ssl
context = ssl.create_default_context()
result = requests.get(url, headers=headers, params=params, verify=context.load_verify_locations(cafile=certifi.where()))
This approach tells requests to use a specific set of trusted certificates. It’s a bit more involved, but it solved the issue for me without compromising security.
If you’re still stuck, it might be worth checking if there’s any firewall or antivirus software interfering with the connection. They can sometimes cause unexpected SSL issues.
Hope this helps! Let us know how it goes.