【发布时间】:2021-01-13 05:48:23
【问题描述】:
在方法 1 中,我希望先执行 try 块,然后希望执行 call_ordercreate 方法,尝试使用 asyncio 但得到错误输出,如描述中所示,我该如何解决这个问题?
方法#1
@app.route("/slack/message_actions", methods=[ "POST" ])
def message_actions():
if (payload[ "type" ] == "view_submission" and payload[ "view" ][ "callback_id" ] == "sthpush"):
print("entered push")
call_ordercreate(thread_ts, user_name) **# Run this method after executing try block**
try:
return jsonify(
{
"response_action": "push",
"view": orderwaitmessage,
}
)
except SlackApiError as e:
code = e.response[ "error" ]
return make_response(f"Failed to open a modal due to {code}", 200)
方法#2
async def call_ordercreate(thread_ts, user_name):
await asyncio.sleep(4)
url_list1 = CONST_ORDERCREATE_API
r = requests.get(url)
错误输出
C:/Users/PycharmProjects/iptautobot-events/newapp.py:263: RuntimeWarning: coroutine 'call_ordercreate' was never awaited
call_ordercreate(thread_ts, user_name)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
【问题讨论】:
标签: python asynchronous flask