🐛Fix invalid string causing server code 500

This commit is contained in:
Evil0ctal 2022-07-18 21:54:32 -07:00 committed by GitHub
parent f161ae3c02
commit e7078b20bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,7 +2,7 @@
# -*- encoding: utf-8 -*- # -*- encoding: utf-8 -*-
# @Author: https://github.com/Evil0ctal/ # @Author: https://github.com/Evil0ctal/
# @Time: 2021/11/06 # @Time: 2021/11/06
# @Update: 2022/07/10 # @Update: 2022/07/18
# @Function: # @Function:
# 创建一个接受提交参数的Flask应用程序。 # 创建一个接受提交参数的Flask应用程序。
# 将scraper.py返回的内容以JSON格式返回。 # 将scraper.py返回的内容以JSON格式返回。
@ -63,7 +63,11 @@ def webapi():
api = Scraper() api = Scraper()
content = request.args.get("url") content = request.args.get("url")
if content != '': if content != '':
post_content = find_url(content)[0] try:
post_content = find_url(content)[0] # 尝试找出提交值中的链接
except:
# 返回错误信息
return jsonify(status='failed', reason="Can not find valid Douyin/TikTok URL", function='webapi()', value=content)
if api_config['Allow_Logs'] == 'True': if api_config['Allow_Logs'] == 'True':
# 将API记录在API_logs.txt中 # 将API记录在API_logs.txt中
date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
@ -91,7 +95,7 @@ def webapi():
return jsonify(status='failed', reason=str(e), time=analyze_time, function='webapi()', value=content) return jsonify(status='failed', reason=str(e), time=analyze_time, function='webapi()', value=content)
else: else:
# 返回错误信息 # 返回错误信息
return jsonify(status='failed', reason='url value cannot be empty', function='api()', value=content) return jsonify(status='failed', reason='url value cannot be empty', function='webapi()', value=content)
@app.route("/ios", methods=["POST", "GET"]) @app.route("/ios", methods=["POST", "GET"])