Forums

FastAPI process integers

Hi, I have the following code

`@app.get("/process_integers_url/")

async def process_integers_url(numbers: List[int] = None):

if numbers is None:

    return {"error": "No numbers provided!"}

result_sum = sum(numbers)
result_product = 1
for num in numbers:
    result_product *= num
return {
    "sum": result_sum,
    "product": result_product,
}`

I want to pass a list of parameters to the process_integers endpoint via the url. However, when I use this URL http://localhost:8000/process_integers/?numbers=1&numbers=2&numbers=3 , I always get the error "No numbers provided". Can someone tell me why this is or how I can fix this problem?

Hi there -- these are the forums for PythonAnywhere, an online development and hosting environment (which unfortunately doesn't support FastAPI yet). We -- the tech support team here -- can only really provide help with PythonAnywhere-specific questions, though perhaps other forum members might be able to contribute. However, you'll probably have more luck getting help on a general coding site like Stack Overflow.