How do I access modern, remote APIs requiring HTTPS?
See original GitHub issueFirst check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
- After submitting this, I commit to:
- Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
Problem
I’m trying to access Food Data Central’s API to retrieve food information, but it tell me I need an HTTPS connection:
usda.base.DataGovApiError: HTTPS_REQUIRED: Requests must be made over HTTPS. Try accessing the API at: https://api.nal.usda.gov/ndb/search?q=eggs&max=10&offset=0&sort=r&api_key={FDC_API_KEY}&format=json
Here’s the code snippet doing the requesting:
@app.post("/")
async def index(request: Request, food_name: str = Form(...)):
eggs = client.search_foods("eggs", 10)
print(next(eggs))
eggs_data = client.get_food_report(eggs.id)
print(eggs_data)
data = requests.get("https://api.nal.usda.gov/ndb/search?q=eggs&max=10&offset=0&sort=r&api_key={FDC_API_KEY}&format=json")
return templates.TemplateResponse("foods.html", context={"request": request, "data": data})
What I’ve tried:
Hoverfly Postman Docker Twisted Trustme OpenSSL http-server one or two others I’ve forgotten
I’ve went through the process of making a CA certificate and importing it to the “Trusted Authorities” certificates file in the MMC manager, as well as just trying to use the trustme module, but browsers, and especially the remote API, won’t accept it. Each of these things failed on me for some reason or another, and I need some way to send secure http requests to the USDA database.
Does anyone know of a free method I could implement quickly for testing?
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Just some general pointers.
This looks like an issue with the client library you’re using, not anything to do with fastapi or SSL on your api?