繁体   English   中英

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

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

所以我的 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}))

它在 postman 中运行良好,但是在前端网站中它给了我以下 2 个错误

CORS-header 'Access-Control-Allow-Origin' is missing这个是合乎逻辑的,因为我的另一个错误使我不返回任何东西

Error TypeError: string indices must be integers这个非常令人困惑,因为我什至不确定这个来自哪里

有没有办法解决这个问题,所以我可以从我的前端网站发布请求到我的 ipnb?

我知道的事情:

将其转换为 GET function 允许它工作但非常不安全

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

暂无
暂无

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

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