我正在尝试在python中创建REST API。我在python中有不错的经验,但是相对于REST API来说还是比较新的……当我运行python脚本时,我的浏览器上出现“内部服务器错误”。
类似这样的东西:
在我的控制台上,我看到了:
Error as displayed on my console
这是我的代码:
from flask import Flask, request
from flask_restful import Resource, Api
import firebase_admin
# For connecting to firestore database and authentication
from firebase_admin import credentials, firestore
# For Data base Connectivity
from firebase_admin import db
from flask import jsonify
app = Flask(__name__)
api = Api(app)
class Firebase_Data(Resource):
def getData(self):
# Setting up credentials to connect
cred = credentials.Certificate(../Path)
# Setting up secure connection to firestore Real time database
app = firebase_admin.initialize_app(cred, {
'projectId' : 'project_ID'
})
# Connecting to the firestore client
db_ref = firestore.client()
# Referring to the '** section of the data
ref_inc = db_ref.collection(u'name of column')
# Fetching all the records under that particular section and
converting them to list of dictionaries
docs = list( ref_inc.get() )
lat_long = []
for doc in docs:
data = doc.to_dict()
lat_long.append(
{ 'Latitude:' : data['latitude'], 'Longitude' :
data['longitude'] } )
return jsonify(lat_long)
api.add_resource(Firebase_Data, '/Firebase_Data') # Route_1
if __name__ == '__main__':
app.run(port=5002)
我基本上是想从Fire store数据库中获取一些数据并将其显示在浏览器上。我不认为火灾存储部分与我的错误有任何关系,我认为我在执行python类的“获取”功能时遗漏了一些东西,我无法弄清楚..任何帮助都是表示赞赏。.预先感谢