From amundsen.craig at gene.com Fri Jun 3 12:38:51 2016 From: amundsen.craig at gene.com (Craig Amundsen) Date: Fri, 3 Jun 2016 09:38:51 -0700 Subject: [Flask] after_insert question Message-ID: Hi - I'm trying to use an after_insert event to do some bookkeeping in a Flask app and am having issues. Before we get too far I've been basing my app on the Grinberg Flask Web Development book. Simplifying wildly, lets say I have these two tables class Foo(db.Model) __tablename__ = 'foos' id = db.Column(db.Integer, primary_key = True) col_one = db.Column(db.String(32)) col_two = db.Column(db.String(32)) @staticmethod def on_change(mapper, connection, target): # save a new row in table Bar class Bar(db.Model) __tablename__ = 'bars' id = db.Column(db.Integer, primary_key = True) col_a = db.Column(db.Integer) col_b = db.Column(db.String(16)) db.event.isent(Foo, 'after_insert', Foo.on_change) I really only want to add the row to Bar if there is an actual write to Foo. I note that if I make the listened-for event before_insert and in the on_change method I do b = Bar(col_a = 5, col_b = 'Hi Craig') db.session.add(b) I get shouty messages in the console, but it works. I see various things when I google for using the connection object in an after_insert event, but nothing that is actually a workable example that I can transmogrify for my actual use. I could put something in the new_foo method in views.py that writes a Bar entry, but I'd like to use the event. Could someone point me in the proper direction for getting a connection.execute call to work? Thanks, - Craig -------------- next part -------------- An HTML attachment was scrubbed... URL: From ahall at autodist.com Tue Jun 7 17:32:58 2016 From: ahall at autodist.com (Alex Hall) Date: Tue, 7 Jun 2016 17:32:58 -0400 Subject: [Flask] No database errors in logs? Message-ID: Hello list, I have my normal setup--Flask served through UWSGI running on Nginx. I'm using FreeTDS to access some MSSQL databases as part of my Flask app, and I recently modified some queries. Now, nothing works, and I'm nearly certain the problem is in the query in question. The problem is that the logs don't show anything; UWSGI shows my Python print statements, but no errors, and Nginx has no errors at all. Sorry if this is a bit OT, but I seem to get the best responses from people on this list rather than UWSGI, which appears sparsely populated these days. If anyone knows of a way I can view the errors coming back from my database, that would be great. I thought exceptions got logged somewhere, but if they are still, I can no longer find them. I suppose it could also be some problem that never triggers an exception, but I'm not sure how that would work. -- Alex Hall Automatic Distributors, IT department ahall at autodist.com -------------- next part -------------- An HTML attachment was scrubbed... URL: From amundsen.craig at gene.com Tue Jun 7 18:12:08 2016 From: amundsen.craig at gene.com (Craig Amundsen) Date: Tue, 7 Jun 2016 15:12:08 -0700 Subject: [Flask] after_insert question In-Reply-To: References: Message-ID: I thought I might answer my own question. I haven't been able to get an elegant solution to this problem. I can get the before_insert and before_update events to do things, but the only way I can get a change in my Foo table to show end up with a new row in the Bar table is to use the connection object's execute method to run some SQL. I didn't like that. The final problem I had with this method is that I need to write the Foo row's primary key into the Bar row. before_insert fires before the Foo row has a primary key. What I did instead was a bit of a kludge, but in my new_foo and edit_foo view methods I call a static method Bar.saveFoo(foo_instance) which creates a new Bar row. I know I could do this with database triggers, but I don't want tie myself to a particular database On Fri, Jun 3, 2016 at 9:38 AM, Craig Amundsen wrote: > Hi - > > I'm trying to use an after_insert event to do some bookkeeping in a Flask > app and am having issues. > > Before we get too far I've been basing my app on the Grinberg Flask Web > Development book. > > Simplifying wildly, lets say I have these two tables > > class Foo(db.Model) > __tablename__ = 'foos' > id = db.Column(db.Integer, primary_key = True) > col_one = db.Column(db.String(32)) > col_two = db.Column(db.String(32)) > > @staticmethod > def on_change(mapper, connection, target): > # save a new row in table Bar > > class Bar(db.Model) > __tablename__ = 'bars' > id = db.Column(db.Integer, primary_key = True) > col_a = db.Column(db.Integer) > col_b = db.Column(db.String(16)) > > db.event.isent(Foo, 'after_insert', Foo.on_change) > > I really only want to add the row to Bar if there is an actual write to > Foo. > > I note that if I make the listened-for event before_insert and in the > on_change method I do > b = Bar(col_a = 5, col_b = 'Hi Craig') > db.session.add(b) > I get shouty messages in the console, but it works. > > I see various things when I google for using the connection object in an > after_insert event, but nothing that is actually a workable example that I > can transmogrify for my actual use. > > I could put something in the new_foo method in views.py that writes a Bar > entry, but I'd like to use the event. > > Could someone point me in the proper direction for getting a > connection.execute call to work? > > Thanks, > - Craig > -------------- next part -------------- An HTML attachment was scrubbed... URL: From braiotta at mit.edu Tue Jun 7 18:26:25 2016 From: braiotta at mit.edu (Christopher M Braiotta) Date: Tue, 7 Jun 2016 22:26:25 +0000 Subject: [Flask] about flask session expire problem In-Reply-To: <201605231628255039599@kiyes.cn> References: <201605231628255039599@kiyes.cn> Message-ID: <726C5B3DD1560404.4AE2A31A-8703-4AB2-9996-9D23A7A43EB8@mail.outlook.com> If it's good enough for that to happen at page load, I feel like the answer would be a route decorator applied to every route that isn't you front page. The decorator checks the status of your session, and upon noticing expiration, issues a redirect to the front page. On Tue, Jun 7, 2016 at 2:39 PM -0400, "wangjia at kiyes.cn" > wrote: hi: I use nginx+uwsgi+flask(0.10.1) build environment , now i want to realize platform return to home page when user session expire , but i dont know how to setting , can you guide me? thanks ________________________________ Best Regards, Venture -------------- next part -------------- An HTML attachment was scrubbed... URL: From patatetom at gmail.com Fri Jun 10 05:52:57 2016 From: patatetom at gmail.com (Pascal) Date: Fri, 10 Jun 2016 11:52:57 +0200 Subject: [Flask] flask url_for / nginx proxy_pass Message-ID: hello, my flask app (flaskbb ) is listening on 127.0.0.1:8765 and is ok when accessed directly with http://127.0.0.1:8765/. when accessed through nginx with http://mywebserver/flaskbb/, all links are broken because /flaskbb is missing in the url (eg. src="/css/..." and not src="/flaskbb/css/..."). I currently bypasses the problem by modifying the templates, but it's not clean :-( how can I solve this problem ? note that nginx directive is location /flaskbb/ { proxy_pass http://127.0.0.1:8765/; } and I can't play with virtual-server/dns. -------------- next part -------------- An HTML attachment was scrubbed... URL: From ub at artfacts.net Fri Jun 10 06:43:58 2016 From: ub at artfacts.net (Ulrich Berthold) Date: Fri, 10 Jun 2016 12:43:58 +0200 Subject: [Flask] flask url_for / nginx proxy_pass In-Reply-To: References: Message-ID: <20160610104358.GA1735@moebius> hey pascal, when using blueprints, you can pass the url prefix as an argument to register_blueprint, like this: app.register_blueprint(api, url_prefix='/api') will make api aceesable under https://my.url/api and urls created with url_for in that context will have the prefix. there is a stackoverflow question, which i think handles your problem: http://stackoverflow.com/questions/18967441/add-a-prefix-to-all-flask-routes cheers, ub On Fri, Jun 10, 2016 at 11:52:57AM +0200, Pascal wrote: > hello, > > my flask app (flaskbb ) is listening on > 127.0.0.1:8765 and is ok when accessed directly with http://127.0.0.1:8765/. > > when accessed through nginx with http://mywebserver/flaskbb/, all links are > broken because /flaskbb is missing in the url (eg. src="/css/..." and not > src="/flaskbb/css/..."). > > I currently bypasses the problem by modifying the templates, but it's not > clean :-( > > how can I solve this problem ? > > note that nginx directive is location /flaskbb/ { proxy_pass > http://127.0.0.1:8765/; } and I can't play with virtual-server/dns. > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: From patatetom at gmail.com Fri Jun 10 08:16:56 2016 From: patatetom at gmail.com (Pascal) Date: Fri, 10 Jun 2016 14:16:56 +0200 Subject: [Flask] flask url_for / nginx proxy_pass In-Reply-To: <20160610104358.GA1735@moebius> References: <20160610104358.GA1735@moebius> Message-ID: thank you for track Ulrich I've changed the url prefixes defined in default.py and used in app.py with register_blueprint. I've also changed nginx directive to location /flaskbb/ { proxy_pass http://127.0.0.1:8765/flaskbb/; }. now links are good :-) except static files like css :-(. for example, this link is made with template layout.html by url_for... 2016-06-10 12:43 GMT+02:00 Ulrich Berthold : > hey pascal, > > when using blueprints, you can pass the url prefix as an argument to > register_blueprint, like this: > > app.register_blueprint(api, url_prefix='/api') > > will make api aceesable under https://my.url/api and urls created with > url_for in that context will have the prefix. > > there is a stackoverflow question, which i think handles your problem: > > http://stackoverflow.com/questions/18967441/add-a-prefix-to-all-flask-routes > > cheers, > ub > > > On Fri, Jun 10, 2016 at 11:52:57AM +0200, Pascal wrote: > > hello, > > > > my flask app (flaskbb ) is listening > on > > 127.0.0.1:8765 and is ok when accessed directly with > http://127.0.0.1:8765/. > > > > when accessed through nginx with http://mywebserver/flaskbb/, all links > are > > broken because /flaskbb is missing in the url (eg. src="/css/..." and not > > src="/flaskbb/css/..."). > > > > I currently bypasses the problem by modifying the templates, but it's not > > clean :-( > > > > how can I solve this problem ? > > > > note that nginx directive is location /flaskbb/ { proxy_pass > > http://127.0.0.1:8765/; } and I can't play with virtual-server/dns. > > > _______________________________________________ > > Flask mailing list > > Flask at python.org > > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From patatetom at gmail.com Fri Jun 10 08:22:08 2016 From: patatetom at gmail.com (Pascal) Date: Fri, 10 Jun 2016 14:22:08 +0200 Subject: [Flask] flask url_for / nginx proxy_pass In-Reply-To: References: <20160610104358.GA1735@moebius> Message-ID: if I manually add /flaskbb in layout.html, the link seems good (eg but flaskbb app return a 404 to nginx on request : 127.0.0.1 - - [10/Jun/2016 14:18:54] "GET /flaskbb/ HTTP/1.0" 200 - 127.0.0.1 - - [10/Jun/2016 14:18:54] "GET /flaskbb/static/css/pygments.css HTTP/1.0" 404 - 127.0.0.1 - - [10/Jun/2016 14:18:54] "GET /flaskbb/static/css/styles.css HTTP/1.0" 404 - 2016-06-10 14:16 GMT+02:00 Pascal : > thank you for track Ulrich > > I've changed the url prefixes defined in default.py > > and used in app.py > > with register_blueprint. > I've also changed nginx directive to location /flaskbb/ { proxy_pass > http://127.0.0.1:8765/flaskbb/; }. > > now links are good :-) except static files like css :-(. > > for example, this link href="/static/css/styles.css"> is made with template layout.html > > by url_for... > > > > 2016-06-10 12:43 GMT+02:00 Ulrich Berthold : > >> hey pascal, >> >> when using blueprints, you can pass the url prefix as an argument to >> register_blueprint, like this: >> >> app.register_blueprint(api, url_prefix='/api') >> >> will make api aceesable under https://my.url/api and urls created with >> url_for in that context will have the prefix. >> >> there is a stackoverflow question, which i think handles your problem: >> >> http://stackoverflow.com/questions/18967441/add-a-prefix-to-all-flask-routes >> >> cheers, >> ub >> >> >> On Fri, Jun 10, 2016 at 11:52:57AM +0200, Pascal wrote: >> > hello, >> > >> > my flask app (flaskbb ) is >> listening on >> > 127.0.0.1:8765 and is ok when accessed directly with >> http://127.0.0.1:8765/. >> > >> > when accessed through nginx with http://mywebserver/flaskbb/, all >> links are >> > broken because /flaskbb is missing in the url (eg. src="/css/..." and >> not >> > src="/flaskbb/css/..."). >> > >> > I currently bypasses the problem by modifying the templates, but it's >> not >> > clean :-( >> > >> > how can I solve this problem ? >> > >> > note that nginx directive is location /flaskbb/ { proxy_pass >> > http://127.0.0.1:8765/; } and I can't play with virtual-server/dns. >> >> > _______________________________________________ >> > Flask mailing list >> > Flask at python.org >> > https://mail.python.org/mailman/listinfo/flask >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jacopo.notarstefano at gmail.com Thu Jun 16 18:04:17 2016 From: jacopo.notarstefano at gmail.com (Jacopo Notarstefano) Date: Fri, 17 Jun 2016 00:04:17 +0200 Subject: [Flask] Flask in debug mode and socket.setdefaulttimeout on Python 2 Message-ID: In the past few months our Flask application was randomly returning EAGAIN errors (error code 11 on Linux or 35 on Mac) on some requests when developing using DEBUG=True. A colleague recently found the cause: we were importing a library which was calling socket.setdefaulttimeout during its initialisation. See here for a minimal reproduction: https://github.com/mihaibivol/isbnlib-flask-error-demo, or see the reproduction on Travis here: https://travis-ci.org/mihaibivol/isbnlib-flask-error-demo/builds/138128020. We can work around this bug by using a different library or switching to Gunicorn for development, so that's not the issue. My purpose for posting is twofold: 1. Informing the Flask users about this, so that, if they've intermittently seen this error, they know they should audit their dependencies for socket.setdefaulttimeout. 2. Notifying the people versed in Flask internals to see if we should file a Flask issue. An interesting side note is that this appears to happen only on Python 2. Cheers, Jacopo Notarstefano From barak.bloch at gmail.com Mon Jun 20 03:42:59 2016 From: barak.bloch at gmail.com (Barak Bloch) Date: Mon, 20 Jun 2016 10:42:59 +0300 Subject: [Flask] invalid transaction -Flask-SQLAlchemy Message-ID: Hey all, I got again the famous error sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back i tried to 1. change to session pool to be zero size (i don't really need it for my app): SQLALCHEMY_POOL_SIZE = 0 2. rollback each teardown_request 3. few different settings and tips from the internet Nothing really helped me. i don't need the pool of connection and really don't need anything but working and stable connection to the DB. the question is: what is the right approach to do when this error happend? Thanks, Barak. -------------- next part -------------- An HTML attachment was scrubbed... URL: From fvillarroel at yahoo.com Wed Jun 22 18:33:41 2016 From: fvillarroel at yahoo.com (FERNANDO VILLARROEL) Date: Wed, 22 Jun 2016 22:33:41 +0000 (UTC) Subject: [Flask] Websocket and form popup References: <484794775.101484.1466634821348.JavaMail.yahoo.ref@mail.yahoo.com> Message-ID: <484794775.101484.1466634821348.JavaMail.yahoo@mail.yahoo.com> I hope you could me explain how i can do the follow idea: If a have a user like 2222 registered on Flask (local intranet) I have another ?application like asterisk (IP PBX) (is running the same machine of Flask) so when asterisk received a inbound a call for user 2222 i need that the browser of user 2222 (only browser of this user) open a form pop with parameters received from external application like phone number......etc. Someone tell me that i must use websockets and tornado. I do not know how i ?do a call to browser of peer 2222 for display a form popup only for this browser (session of user 2222) using websocket. It's possible to do with Flask, and if it's possible give some example or idea how i can do. I was reading? http://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent Kind regards. -------------- next part -------------- An HTML attachment was scrubbed... URL: From okelet at gmail.com Thu Jun 23 17:57:57 2016 From: okelet at gmail.com (=?UTF-8?Q?Juan_Asensio_S=C3=A1nchez?=) Date: Thu, 23 Jun 2016 23:57:57 +0200 Subject: [Flask] Update GTK menu from Web Flask App Message-ID: [I have posted this same question on stackoverflow, http://stackoverflow.com/questions/37979079/update-gtk-menu-from-web-flask-app, with no responses; i hope to be more lucky here] Addition: I suppose this problem is something related to the app context, but I can't imagine how to make this work. Hi all I am trying to create an Ubuntu indicator, that launches a Flask app in a separate thread (using multiprocessing.Process), and from an action in the Flask app, add an item to the indicator menu (in this simplified code, just when the root page is loaded, a menu item with the current datetime should be created). The problem is that although I get no errors, the menu is not created. I am using GLib.idle_add as recommended in other places without success. This is the code: #!/usr/bin/env python # -*- coding: UTF-8 -*- import argparse from datetime import datetime from flask import Flask from multiprocessing import Process import signal import gi gi.require_version('Gtk', '3.0') gi.require_version('AppIndicator3', '0.1') from gi.repository import Gtk, GLib, AppIndicator3 APP_ID = "test" APP_ICON = "test" class GtkFlaskIndicatorTest(object): def __init__(self, debug): self.indicator = AppIndicator3.Indicator.new(APP_ID, APP_ICON, AppIndicator3.IndicatorCategory.APPLICATION_STATUS) self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) GLib.threads_init() self.app = GtkFlaskApp(self, debug) self.app.start_app() self.menu = None self.quit_menu_item = None self.build_menu() Gtk.main() def build_menu(self): self.menu = Gtk.Menu() self.quit_menu_item = Gtk.MenuItem(u"Quit") self.quit_menu_item.connect('activate', self.quit) self.menu.append(self.quit_menu_item) self.menu.show_all() self.indicator.set_menu(self.menu) def add_menu_item(self, text): print "add_menu_item: " + text GLib.idle_add(self.add_menu_item_cb, text) def add_menu_item_cb(self, text): print "add_menu_item_cb: " + text item = Gtk.MenuItem(text) self.menu.append(item) self.menu.show_all() def quit_control_c(self, signal, frame): self.quit(None) def quit(self, source): self.app.stop_app() Gtk.main_quit() class GtkFlaskApp(object): def __init__(self, indicator, debug): self.indicator = indicator self.debug = debug self.app = Flask("GtkFlaskFlaskApp") self.app.add_url_rule('/', 'test', self.test) def test(self): text = str(datetime.now()) self.indicator.add_menu_item(text) return text def start_app(self): self.app_server = Process(target=self.start_app_thread) self.app_server.start() def start_app_thread(self): self.app.run(port=8888, debug=self.debug, use_reloader=False) if __name__ == "__main__": signal.signal(signal.SIGINT, signal.SIG_DFL) parser = argparse.ArgumentParser() parser.add_argument('--debug', action='store_true') args = parser.parse_args() GtkFlaskIndicatorTest(args.debug) -------------- next part -------------- An HTML attachment was scrubbed... URL: From okelet at gmail.com Fri Jun 24 13:33:04 2016 From: okelet at gmail.com (=?UTF-8?Q?Juan_Asensio_S=C3=A1nchez?=) Date: Fri, 24 Jun 2016 19:33:04 +0200 Subject: [Flask] Update GTK menu from Web Flask App In-Reply-To: References: Message-ID: Solved, it was all about the module `multiprocessing.Process`. Replaced with `threading.Thread` and everything works fine now. 2016-06-23 23:57 GMT+02:00 Juan Asensio S?nchez : > [I have posted this same question on stackoverflow, > http://stackoverflow.com/questions/37979079/update-gtk-menu-from-web-flask-app, > with no responses; i hope to be more lucky here] > > Addition: I suppose this problem is something related to the app context, > but I can't imagine how to make this work. > > Hi all > > I am trying to create an Ubuntu indicator, that launches a Flask app in a > separate thread (using multiprocessing.Process), and from an action in the > Flask app, add an item to the indicator menu (in this simplified code, just > when the root page is loaded, a menu item with the current datetime should > be created). The problem is that although I get no errors, the menu is not > created. I am using GLib.idle_add as recommended in other places without > success. This is the code: > > #!/usr/bin/env python > # -*- coding: UTF-8 -*- > > import argparse > from datetime import datetime > from flask import Flask > from multiprocessing import Process > import signal > > import gi > gi.require_version('Gtk', '3.0') > gi.require_version('AppIndicator3', '0.1') > from gi.repository import Gtk, GLib, AppIndicator3 > > > APP_ID = "test" > APP_ICON = "test" > > class GtkFlaskIndicatorTest(object): > > def __init__(self, debug): > > self.indicator = AppIndicator3.Indicator.new(APP_ID, APP_ICON, > AppIndicator3.IndicatorCategory.APPLICATION_STATUS) > self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) > > GLib.threads_init() > > self.app = GtkFlaskApp(self, debug) > self.app.start_app() > > self.menu = None > self.quit_menu_item = None > self.build_menu() > > Gtk.main() > > def build_menu(self): > > self.menu = Gtk.Menu() > > self.quit_menu_item = Gtk.MenuItem(u"Quit") > self.quit_menu_item.connect('activate', self.quit) > self.menu.append(self.quit_menu_item) > > self.menu.show_all() > self.indicator.set_menu(self.menu) > > def add_menu_item(self, text): > print "add_menu_item: " + text > GLib.idle_add(self.add_menu_item_cb, text) > > def add_menu_item_cb(self, text): > print "add_menu_item_cb: " + text > item = Gtk.MenuItem(text) > self.menu.append(item) > self.menu.show_all() > > def quit_control_c(self, signal, frame): > self.quit(None) > > def quit(self, source): > self.app.stop_app() > Gtk.main_quit() > > > class GtkFlaskApp(object): > > def __init__(self, indicator, debug): > self.indicator = indicator > self.debug = debug > self.app = Flask("GtkFlaskFlaskApp") > self.app.add_url_rule('/', 'test', self.test) > > def test(self): > text = str(datetime.now()) > self.indicator.add_menu_item(text) > return text > > def start_app(self): > self.app_server = Process(target=self.start_app_thread) > self.app_server.start() > > def start_app_thread(self): > self.app.run(port=8888, debug=self.debug, use_reloader=False) > > > if __name__ == "__main__": > > signal.signal(signal.SIGINT, signal.SIG_DFL) > > parser = argparse.ArgumentParser() > parser.add_argument('--debug', action='store_true') > args = parser.parse_args() > > GtkFlaskIndicatorTest(args.debug) > -------------- next part -------------- An HTML attachment was scrubbed... URL: