Error TypeError: string indices must be integers json jupyter kernel gateway

79 views Asked by At

So i have a small api in my ipynb with the following code

# POST /convert
req = json.loads(REQUEST)
args = req['body']
print(args['angle'])

angle = args['angle']
converted = math.radians(angle)
print(json.dumps({'convertedAngle': converted}))

and it works fine in postman however in the frontend website it gives me the following 2 errors

CORS-header ‘Access-Control-Allow-Origin’ is missing this one is logical as my other error makes it so that i dont return anything

Error TypeError: string indices must be integers this one is highly confusing as i am not even sure where this one comes from

is there a way to fix this problem so i can do post requests from my frontend website to my ipnb?

things i know that work:

converting it to a GET function allows it to work but is quite unsecure

postman with the following curl request:

curl --location --request POST 'http://127.0.0.1:8889/convert' \
--header 'Content-Type: application/json' \
--data-raw '{
    "angle": 180
}'
1

There are 1 answers

0
confusedstudent On

k so i figured it out the problem was the pre flight options request from CORS it refused to send the correct cors headers back because you need to set that up in config or with the following long command in your anaconda prompt jupyter kernelgateway --KernelGatewayApp.api='kernel_gateway.notebook_http' --KernelGatewayApp.seed_uri='api.ipynb' --KernelGatewayApp.allow_headers="*" --KernelGatewayApp.allow_origin='*'