When I reference another endpoint inside an async
function in my FastAPI script, that endpoint will hang and fail to load. Despite http://127.0.0.1:8000/data?nums=1&nums=2&nums=3
returning the correct url (can test by changing the return statement to return url
), the request hangs and also does not output anything to the terminal for debugging. How can I take parameter data and feed those values into another endpoint in FastAPI? Thanks!
from fastapi import FastAPI, Query
from typing import List
import requests
app = FastAPI()
@app.get('/data')
async def test_data(nums: List[int] = Query(...)):
return [nums[i] * 2 for i in range(len(nums))]
@app.get('/load_data')
async def load_data(nums: List[int] = Query(...)):
url = 'http://127.0.0.1:8000/data?'
for i in range(len(nums)):
url += f'nums={nums[i]}&'
return requests.get(url).json()
# uvicorn reprex:app --reload
# http://127.0.0.1:8000/data?nums=1&nums=2&nums=3
# this will result in a hung request call