gpt4 book ai didi

python - 类型错误 : 'dict_keyiterator' object is not subscriptable

转载 作者:行者123 更新时间:2023-11-28 22:24:19 24 4
gpt4 key购买 nike

<分区>

我试着在这里学习这个教程 https://www.codementor.io/jadianes/building-a-web-service-with-apache-spark-flask-example-app-part2-du1083854

使用 spark,flask 我尝试在 win 10 中使用带有这行代码的 cmd 发送带有 curl 的文件 user_ratings.file

curl --data-binary @user_ratings.file http://127.0.0.1:5432/0/ratings

文件没有格式只有这个数据

260,9 1,8 16,7 25,8 32,9 335,4 379,3 296,7 858,10 50,8

post的功能是

@main.route("/<int:user_id>/ratings", methods=["POST"])
def add_ratings(user_id):
# get the ratings from the Flask POST request object
ratings_list = request.form.keys()[0].strip().split("\n")
ratings_list = map(lambda x: x.split(","), ratings_list)
# create a list with the format required by the negine (user_id, movie_id, rating)
ratings = map(lambda x: (user_id, int(x[0]), float(x[1])), ratings_list)
# add them to the model using then engine API
recommendation_engine.add_ratings(ratings)

return json.dumps(ratings)

但它不会发送任何薄的 csv 文件 Spark 消息错误是

 File "C:\Users\ibrahim\Desktop\RSS\app.py", line 33, in add_ratings
ratings_list = request.form.keys()[0].strip().split("\n")
TypeError: 'dict_keyiterator' object is not subscriptable
127.0.0.1 - - [26/Sep/2017:23:46:48 +0200] "POST /0/ratings HTTP/1.1" 500 291 "-" "curl/7.55.1"

我似乎在函数中有这一行

 ratings_list = request.form.keys()[0].strip().split("\n")

在教程中它将数据发布到 csv 文件任何帮助,谢谢大家

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com