简体   繁体   中英

Request using POST method returns a none value

I am trying to get APScheduler to return the list of jobs but it always returns a none value.

main.py:

def test():
    print("test")


app = Flask(__name__)
scheduler.add_job(func=test, trigger='cron', hour='11', minute= '36')
scheduler.start() 

@app.route('/viewjobs', methods=['POST'])
def view():
    if request.method == 'POST':
            
        string = str(scheduler.print_jobs())                   
        return(string)

if __name == '__main__':
    app.run()

Now when i send a POST request using curl i get None. what am i doing wrong?

If you look at the documentation , it clearly says that print_jobs() prints a formatted list of jobs to the standard output. The function call returns None . A quick fix would be to use a StringIO object as the output sink and return its contents:

buffer = io.StringIO()
scheduler.print_jobs(out=buffer)
return buffer.getvalue()

Disclaimer: I have not tested this in practice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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