简体   繁体   English

Flask的Javascript REST API错误

[英]Javascript REST API Error with Flask

I have deployed a flask framework on the pythonanywhere website, with the following code, whose third method handles rest requests: 我已经在pythonanywhere网站上部署了一个flask框架,带有以下代码,该代码的第三个方法处理其余请求:

from flask import Flask
from flask import jsonify
app = Flask(__name__)
@app.route('/')
def hello_world():
    return 'Hello from Sachin Flask!'
@app.route('/getval')
def getter():
    return '3'
@app.route('/get', methods=['GET'])
def get_task():
    return jsonify({"tasks": "tas",})

Website: https://sachk480.pythonanywhere.com/ 网站: https//sachk480.pythonanywhere.com/

I wrote a simple javascript getter which grabs the data from the /get url and displays it to the console, but I keep receiving this error: 我写了一个简单的javascript getter,它从/ get url中获取数据并将其显示在控制台上,但是我一直收到此错误:

Uncaught SyntaxError: Unexpected token : 未捕获到的SyntaxError:意外令牌:

This error points to the JSON data and its format, and I am not sure what is going wrong here. 此错误指向JSON数据及其格式,我不确定这里出了什么问题。

Javascript getter: https://jsfiddle.net/sachinkonan480/04bx0sye/5/ Javascript getter: https//jsfiddle.net/sachinkonan480/04bx0sye/5/

PythonAnywhere dev here, when I visit your site I see an error: 这里的PythonAnywhere开发人员,当我访问您的网站时,我看到一个错误:

https://sachk480.pythonanywhere.com/get https://sachk480.pythonanywhere.com/get

My guess is that your app is actually returning a 500 error, which is not valid json, so that's why your javascript can't parse it. 我的猜测是您的应用实际上返回了500错误,该错误不是有效的json,所以这就是您的JavaScript无法解析它的原因。

have a look at your error log on pythonanywhere? 看看您在pythonanywhere上的错误日志? there's a few tips on debugging common problems here: http://help.pythonanywhere.com/pages/DebuggingImportError 这里有一些调试常见问题的技巧: http : //help.pythonanywhere.com/pages/DebuggingImportError

问题是您的字典中最后一个值后面有逗号,这不是有效的json

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

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