简体   繁体   English

错误类型错误:字符串索引必须是整数 json jupyter kernel 网关

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

So i have a small api in my ipynb with the following code所以我的 ipynb 中有一个小的 api,代码如下

# 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它在 postman 中运行良好,但是在前端网站中它给了我以下 2 个错误

CORS-header 'Access-Control-Allow-Origin' is missing this one is logical as my other error makes it so that i dont return anything CORS-header 'Access-Control-Allow-Origin' is missing这个是合乎逻辑的,因为我的另一个错误使我不返回任何东西

Error TypeError: string indices must be integers this one is highly confusing as i am not even sure where this one comes from Error TypeError: string indices must be integers这个非常令人困惑,因为我什至不确定这个来自哪里

is there a way to fix this problem so i can do post requests from my frontend website to my ipnb?有没有办法解决这个问题,所以我可以从我的前端网站发布请求到我的 ipnb?

things i know that work:我知道的事情:

converting it to a GET function allows it to work but is quite unsecure将其转换为 GET function 允许它工作但非常不安全

postman with the following curl request: postman 与以下 curl 请求:

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

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='*' 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='*'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM