Python POST api给出错误。找不到日志

Python POST api给出错误。找不到日志,python,rest,api,amazon-web-services,post,Python,Rest,Api,Amazon Web Services,Post,我是python新手。我使用下面提到的链接中的步骤在AWS上部署了一个python POST api api给出了内部服务器错误,并且没有打印日志。是否有我丢失的目录,或者我可以以某种方式打印日志 此外,如果有人能够帮助解决API可能存在的问题: #!/usr/bin/env python2.7 #!flask/bin/python #!/usr/bin/python import numpy import sys,os import codecs import json import pho

我是python新手。我使用下面提到的链接中的步骤在AWS上部署了一个python POST api

api给出了内部服务器错误,并且没有打印日志。是否有我丢失的目录,或者我可以以某种方式打印日志

此外,如果有人能够帮助解决API可能存在的问题:

#!/usr/bin/env python2.7
#!flask/bin/python
#!/usr/bin/python
import numpy
import sys,os
import codecs
import json
import phonetics
import transliteration
import jellyfish
import traceback
from pyjarowinkler import distance
from flask import Flask, jsonify, request
import panphon.distance
from datetime import datetime
from flask_cors import CORS


def obj_dict(obj):
    return obj.__dict__

# logFile = open('log.txt','a')

app = Flask(__name__)
cors = CORS(app, resources={r"/todo/api/*": {"origins": "*"}})

@app.route('/todo/api/v1.0/tasks', methods=['GET''POST'])
def get_tasks():
    if request.method == 'GET':
        return "done with get request"

    elif request.method == 'POST':
        try :
            content = request.get_json()
            with codecs.open('words.txt', 'a') as file:
                for line in content['words']:
                    file.write("\n"+line.encode('utf-8'))

        except Exception:
            with open('log.txt','a') as logger:
                logger.write("At "+str(datetime.now())+" "+traceback.format_exc())
                logger.write("\n\n")

        return "done"

if __name__ == '__main__':
    import logging
    logging.basicConfig(filename='log.txt',level=logging.DEBUG)
    app.run(host='0.0.0.0', debug = False)

注:其他进口产品用于其他用途。我需要POST API才能工作。

尝试设置
debug=True

例如

如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
导入日志记录
logging.basicConfig(filename='log.txt',level=logging.DEBUG)
app.run(host='0.0.0.0',debug=True)

此外,您不需要导入日志记录,因为您可以使用flask的记录器,该记录器应该可以使用
app.logger

如果这是生产,则不建议使用
debug=True
。 如果未设置日志级别,Flask将错误视为默认日志级别 因此,您可以尝试使用
app.logger.setLevel(logging.DEBUG)


已经试过了,但是当我在本地运行它时,日志会被打印出来,而不是在AWSon AWS上。你是用uwsgi运行它还是用单机运行?用uwsgi运行它。我已经发布了我跟随运行它的digital ocean博客的链接。好的,我将尝试使用上面的代码重新创建该问题。我还注意到
路线
方法
应该是
['GET','POST']
缺少一个逗号。@techinjection我已经更新了上面的答案,试着试一试。
@app.route('/todo/api/v1.0/tasks', methods=['GET', 'POST'])
def get_tasks():
    if request.method == 'GET':
        return "done with get request"

    elif request.method == 'POST':
        try :
            content = json.loads(request.get_data())
            with codecs.open('words.txt', 'a') as file:
                for line in content['words']:
                    file.write("\n"+line.encode('utf-8'))

        except Exception:
            with open('log.txt','a') as logger:
                logger.write("At "+str(datetime.now())+" "+traceback.format_exc())
                logger.write("\n\n")

        return "done"