1

我创建了我的烧瓶应用程序来连接 mongodb 并根据 api 方法从集合中检索信息。

这是我的代码:

from flask import Flask, jsonify, request
from flask_pymongo import PyMongo
import re

app = Flask(__name__)


app.config['MONGO_DBNAME'] = 'mydb'
app.config['MONGO_URI'] = 'mongodb://user:pwd@ds157711.mlab.com:57711/mydb'


mongo = PyMongo(app)

@app.route('/framework', methods=['GET'])
def get_all_frameworks():
    framework = mongo.db.mydb 

    output = []

    for q in framework.find():

        output.append({"_id": q["_id"], "username":q["username"],
    return jsonify({'result':output})

@app.route('/product/<name>', methods=['GET'])
def get_one_framework(name):
    framework = mongo.db.offers


    result=[]
    for q in framework.find({"product": {'$regex':name,'$options':'i'}}):
       # print(type(q))
        #   print(q)
        result.append(q)
    if len(result)!=0:
        return jsonify({"result":result})
    else:
        return "no matching results"

@app.route('/seller/<name>',methods=["GET"])
def seller_record(name):
    framework=mongo.db.offers
    q=framework.find_one({'seller':name})
    if q:
        return jsonify(q)
    else:
        return "No seller found for {}".format(name)

我跑了zappa init and zappa deploy dev,得到了网址。

但是,当我运行网址时,https://abcd.execute-api.us-east-2.amazonaws.com/dev/framework

我收到以下错误:

"{'message': 'An uncaught exception happened while servicing this request. 
You can investigate this with the `zappa tail` command.', 'traceback': ['Traceback 
(most recent call last):\\n', '  File \"/var/task/handler.py\", line 452, in handler\\n
    response = Response.from_app(self.wsgi_app, environ)\\n', '  File \"/var/task/werkzeug/wrappers.py\",
    line 903, in from_app\\n    return cls(*_run_wsgi_app(app, environ, buffered))\\n', '  
    File \"/var/task/werkzeug/test.py\", line 884, in run_wsgi_app\\n    
    app_rv = app(environ, start_response)\\n', \"TypeError: 'NoneType' object is not callable\\n\"]}"

这是我的 zappa.json 文件:

{
"dev": {
    "app_function": "mongo.app",
    "aws_region": "us-east-2",
    "profile_name": "default",
    "project_name": "flask-app",
    "runtime": "python3.6",
    "s3_bucket": "zappa-sv1q69rhp"
},
"dev_ap_northeast_1": {
    "aws_region": "ap-northeast-1",
    "extends": "dev"
},
"dev_ap_northeast_2": {
    "aws_region": "ap-northeast-2",
    "extends": "dev"
},
"dev_ap_south_1": {
    "aws_region": "ap-south-1",
    "extends": "dev"
},
"dev_ap_southeast_1": {
    "aws_region": "ap-southeast-1",
    "extends": "dev"
},
"dev_ap_southeast_2": {
    "aws_region": "ap-southeast-2",
    "extends": "dev"
},
"dev_eu_central_1": {
    "aws_region": "eu-central-1",
    "extends": "dev"
},
"dev_eu_west_1": {
    "aws_region": "eu-west-1",
    "extends": "dev"
},
"dev_eu_west_2": {
    "aws_region": "eu-west-2",
    "extends": "dev"
},
"dev_us_east_1": {
    "aws_region": "us-east-1",
    "extends": "dev"
},
"dev_us_west_1": {
    "aws_region": "us-west-1",
    "extends": "dev"
},
"dev_us_west_2": {
    "aws_region": "us-west-2",
    "extends": "dev"
}
}

请帮忙。提前致谢。扎帕尾巴也不起作用

4

0 回答 0