python-3.x - 从 AJAX 向 Flask 发出 POST 请求时出现 500 响应
问题描述
下面是我的functions.js文件
var count = 1;
// get a tweet from backend
function display_tweet(){
var req = {
"index": count
}
.ajax({
type: "POST",
url: "get_tweet",
data: '{"id":"' + count+'}',
dataType: "json",
success: function(data) {
alert(data.d);
},
error: function(data){
alert("fail");
}
});
}
下面是我的 python app.py 文件
@app.route('/get_tweet',methods = ['POST'])
def get_tweet():
#user_agent_received = request.get_json()
#print("request is ",request.form)
print("request ",request.get_json())
global data_dict
print(data_dict)
input_map = dict(request.form.to_dict())
print(input_map)
index=input_map['index']
index=int(str(index))
final_dic={}
final_dic["text"]=data_dict[index]["tweet"]["full_text"]
return json.dumps(final_dic)
下面是我的 index.html 文件中的存根
<div class="tweet">
<div class="data">
<button onclick="display_tweet()">display a new tweet</button>
<div id="fulltextt"></div>
</div>
我不断在后端收到一个带有 500 个内部错误的空 json,看起来像这样。请有人帮忙
{}
127.0.0.1 - - [04/Feb/2020 23:02:07] "POST /get_tweet HTTP/1.1" 500 -
解决方案
推荐阅读
- powerbi - 如何从 Power BI 中的列表中获取第 N 个值?
- linux - 如何正确地通过 pthread_self() 整理?
- python - 结果不一致,Python 中的简单石头剪刀布游戏
- javascript - PHP 清除 $_POST 数据。页面刷新时防止表单重新提交
- javascript - 如何使附加的项目可以在另一个可拖动部分中拖动 - JQUERY
- python - 破折号中图形的条件更新
- node.js - 为什么我在终端中得到 ECONNRESET,但在浏览器中没有?
- java - Java 运行时版本
- javascript - 如何在 v-for 循环中匹配两个数组的并集
- r - Rmarkdown脚注和页面末尾之间的大空白空间