I am trying to pass a URL endpoint to a service root as utf8 encoded string.
The URL I am trying to pass is (my public URL): https://fast-api-test-app-f922f0fd9a50.herokuapp.com/process_numbers
Service root: http://194.182.164.40/ with X-auth (which I have but won’t post here).
I have tried the following:
http -v --raw="https://fast-api-test-app-f922f0fd9a50.herokuapp.com/process_numbers" http://194.182.164.40/ x-auth:....
But keep getting this error:
POST / HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate, br, zstd
Connection: keep-alive
Content-Length: 68
Content-Type: application/json
Host: 194.182.164.40
User-Agent: HTTPie/3.2.3
x-auth: .....
https://fast-api-test-app-f922f0fd9a50.herokuapp.com/process_numbers
HTTP/1.1 200 OK
content-encoding: gzip
content-type: text/plain; charset=utf-8
date: Wed, 04 Sep 2024 13:47:14 GMT
proxy-connection: Keep-Alive
transfer-encoding: chunked
vary: Accept-Encoding
via: Proxy
strconv.Atoi: parsing "{"detail":[{"type":"model_attributes_type","loc":["body"],"msg":"Input should be a valid dictionary or object to extract fields from","input":[1505300953,870029484,435524845,921065621,1199385275,2108789265,708644345,986056738,749334732,1007190513]}]}": invalid syntax
The code for the public URL is:
from fastapi import FastAPI, HTTPException
from fastapi.responses import PlainTextResponse
from pydantic import BaseModel
from typing import List
app = FastAPI()
class ListRequest(BaseModel):
numbers: List[int]
@app.post("/process_numbers", response_class=PlainTextResponse)
async def process_numbers(request: ListRequest):
int32_min = -2**31
int32_max = 2**31 - 1
for number in request.numbers:
if not (int32_min <= number <= int32_max):
raise HTTPException(status_code=400,detail="All elements must be int32 numbers")
result = sum(request.detail.input)
return f"Sum of numbers: {result}"
I am expecting it to return a code which I will use for something.
What could be the issue?
2