Flask

python-flask handling application errors

。_饼干妹妹 提交于 2021-01-25 06:34:13
问题 I've built a flask application and I try to catch unhandled application errors from my routes using the errorhandler decorator. I've a main.py which looks like this, app = Flask(__name__) api = Api(app) api.add_resource(Ping, '/ping') @app.errorhandler(500) def internal_server_error(error): print "caught internal server error" return "This page does not exist", 500 The route Ping is in another file, here is a sample version of the file class Ping(Resource): def get(self): raise return {}, 200

python-flask handling application errors

独自空忆成欢 提交于 2021-01-25 06:33:12
问题 I've built a flask application and I try to catch unhandled application errors from my routes using the errorhandler decorator. I've a main.py which looks like this, app = Flask(__name__) api = Api(app) api.add_resource(Ping, '/ping') @app.errorhandler(500) def internal_server_error(error): print "caught internal server error" return "This page does not exist", 500 The route Ping is in another file, here is a sample version of the file class Ping(Resource): def get(self): raise return {}, 200

python-flask handling application errors

让人想犯罪 __ 提交于 2021-01-25 06:32:52
问题 I've built a flask application and I try to catch unhandled application errors from my routes using the errorhandler decorator. I've a main.py which looks like this, app = Flask(__name__) api = Api(app) api.add_resource(Ping, '/ping') @app.errorhandler(500) def internal_server_error(error): print "caught internal server error" return "This page does not exist", 500 The route Ping is in another file, here is a sample version of the file class Ping(Resource): def get(self): raise return {}, 200

Python authlib flask - how to do password grant flow correctly?

和自甴很熟 提交于 2021-01-25 06:02:00
问题 I have "password grant flow" login with the authlib flask integration working nicely: @app.route('/login', methods=('GET', 'POST')) def login(): if request.method == 'GET': return render_template('login.html') else: try: token = oauth.myOauth2.fetch_access_token(username=request.form.get('username'), password=request.form.get('password')) except OAuthError as e: if e.description: flash(e.description) return render_template('login.html') raise However, in a previous question I was advised not

Python authlib flask - how to do password grant flow correctly?

。_饼干妹妹 提交于 2021-01-25 06:01:29
问题 I have "password grant flow" login with the authlib flask integration working nicely: @app.route('/login', methods=('GET', 'POST')) def login(): if request.method == 'GET': return render_template('login.html') else: try: token = oauth.myOauth2.fetch_access_token(username=request.form.get('username'), password=request.form.get('password')) except OAuthError as e: if e.description: flash(e.description) return render_template('login.html') raise However, in a previous question I was advised not

flask_cors is registered but still getting CORS error

余生长醉 提交于 2021-01-25 04:10:02
问题 I have a Vue frontend that uses Axios to POST to my Flask API. I've registered flask_cors to my Flask instance but I'm still get a CORS error. flask_cors registered in app/__init__.py from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from config import Config from flask_marshmallow import Marshmallow from flask_cors import CORS app = Flask(__name__) app.config.from_object(Config) cors = CORS(app) db = SQLAlchemy(app) migrate = Migrate(app, db)

flask_cors is registered but still getting CORS error

ぃ、小莉子 提交于 2021-01-25 04:09:11
问题 I have a Vue frontend that uses Axios to POST to my Flask API. I've registered flask_cors to my Flask instance but I'm still get a CORS error. flask_cors registered in app/__init__.py from flask import Flask from flask_sqlalchemy import SQLAlchemy from flask_migrate import Migrate from config import Config from flask_marshmallow import Marshmallow from flask_cors import CORS app = Flask(__name__) app.config.from_object(Config) cors = CORS(app) db = SQLAlchemy(app) migrate = Migrate(app, db)

Python基础系列(一)搞懂json数据解析与字典之间的关系

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-24 18:28:13
是不是一直傻傻分不清楚dumps、dump、loads和load的关系,长痛不如短痛,今天索性就把它写明白,不懂得朋友,请看下面。 这里我先回答一个很常见的问题,为什么 Python 会有四个操作 Json 的函数?按理说应该就只有两个的,一个解码,一个编码。 首先 Json 是一种数据格式,文件通常是以 .json 作为后缀,这种结构在互联网很是常见和方便。Python 这么牛逼,也想添加这个结构性的数据,所以 dict 字典数据类型就这么来了, dict 也是键和键值的结构,和 Json 几乎一致。 但是问题了,Json 文件这么的流行,Python 也需要支持 Json文件 的读取和写入的,所以 json.load() 和 json.dump() ,就这么被设计出来了。 但是随着Python爬虫的兴起,越来越多的 Python 爬虫需要处理网站抓取的 json 数据,进行处理转换为 Python 字典类型,但是现有的 load 和 dump 并不能解决这样的问题,所以此时 json.loads() 和 json.dumps() 隆重登场。 详细的介绍请看下方: 1、json.dumps() import json dict1 = { 'name': '西园公子', 'salary': '66666', } json_str = json.dumps(dict1) #

Flask, Python - Increase timeout length on Heroku app [duplicate]

此生再无相见时 提交于 2021-01-22 09:23:58
问题 This question already has answers here : How to change default request time out on Heroku? (3 answers) Closed 4 days ago . I'm building a web app using Flask and hosting it on Heroku. My app scrapes the web—so it can take anywhere from a few seconds to 20 minutes, depending on the search criteria. When I try to run bigger requests, the application times out after the default 30 seconds. Does anyone know how to increase the timeout length? I've tried changing the Profile from this: web:

Flask, Python - Increase timeout length on Heroku app [duplicate]

假如想象 提交于 2021-01-22 09:22:13
问题 This question already has answers here : How to change default request time out on Heroku? (3 answers) Closed 4 days ago . I'm building a web app using Flask and hosting it on Heroku. My app scrapes the web—so it can take anywhere from a few seconds to 20 minutes, depending on the search criteria. When I try to run bigger requests, the application times out after the default 30 seconds. Does anyone know how to increase the timeout length? I've tried changing the Profile from this: web: