1

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?

shaik moeed
  • 5,300
  • 1
  • 18
  • 54
gensC94
  • 11
  • 2
  • What happens if you only give the parameter name once? I.e. http://localhost:8000/process_integers_url/?numbers=1,2,3 – Ada Aug 30 '23 at 10:00
  • Related answers, in addition to the link provided at the top of this question, can be found [here](https://stackoverflow.com/a/73067473/17865804), [here](https://stackoverflow.com/a/73982479/17865804), as well as [here](https://stackoverflow.com/a/70845425/17865804) and [here](https://stackoverflow.com/a/71554017/17865804) – Chris Aug 30 '23 at 11:29

0 Answers0