From gergely at polonkai.eu Thu Feb 1 00:22:33 2018 From: gergely at polonkai.eu (Gergely Polonkai) Date: Thu, 01 Feb 2018 05:22:33 +0000 Subject: [Flask] Help with simple example using AngularJS In-Reply-To: References: Message-ID: Hello, request.form is an ImmutableMultiDict. You can simply subscript it like first_name = request.form['first_name'] given the name of the HTML form field is first_name. No to_dict() or other black magic is needed (well, not unless you have multiple fields with the same name). Best, Gergely On Thu, Feb 1, 2018, 01:19 Clint Olsen wrote: > Hi: > > I should probably add that before I tried messing around with decoding the > form, I just blurted out the object on the receiving side and got: > > from flask import Flask, request, send_file > > app = Flask(__name__) > > @app.route('/', methods=['GET', 'POST']) > def index(): > print('Request: %s' % request.method) > if request.method == 'POST': > data = request.form #.to_dict() > print('First name from form is %s' % data) > return 'OK' > else: > return send_file("static/index.html") > > if __name__ == "__main__": > app.run(host='0.0.0.0', debug=True) > > First name from form is > ImmutableMultiDict([('{"non-stringify":"asdfasdf"}', '')]) > > So, even prior to attempt digging the info out of this structure I see the > issue. > > Thanks, > > -Clint > > On Mon, Jan 29, 2018 at 4:52 PM, Clint Olsen > wrote: > >> Hi: >> >> I'm new to Flask and Angular and only done a little web-based >> programming, so please forgive my lack of understanding. I've just cobbled >> together examples from Flask as well as some examples online to come up >> with the following. >> >> I am interested in the most basic functionality of modifying a web form >> and capturing that in the back-end to prove I can get data at least in one >> direction: >> >> *static/app.js*: >> >> var app = angular.module('myApp', []); >> >> app.controller('formCtrl', function($scope, $log, $http) { >> $scope.firstName = "John"; >> >> $scope.SendData = function () { >> var data = { 'foo': $scope.firstName }; >> >> var config = { >> headers : { >> 'Content-Type': >> 'application/x-www-form-urlencoded;charset=utf-8;' >> } >> } >> >> $http.post('/', data, config) >> .success(function(results) { >> $log.log(results); >> }) >> .error(function(error) { >> $log.log(error); >> }); >> }; >> }); >> >> *static/index.html*: >> >> >> >> >> >> >> >> >> >> >>
>>
>> First Name: >> >> >>
>> >>

You entered: {{firstName}}

>> >>
>> >> >> >> *app.py*: >> >> from flask import Flask, request, send_file >> >> app = Flask(__name__) >> >> @app.route('/', methods=['GET', 'POST']) >> def index(): >> print('Request: %s' % request.method) >> if request.method == 'POST': >> data = request.form.to_dict() >> print('First name from form is %s' % data) >> return 'OK' >> else: >> return send_file("static/index.html") >> >> if __name__ == "__main__": >> app.run(host='0.0.0.0', debug=True) >> >> This code (sort of) works, but the message I get from index() is kind of >> weird, so maybe I'm not packaging the data payload correctly? In this >> example I just populate the form with a "C": >> >> Flask log: >> >> Request: GET >> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /? HTTP/1.1" 200 - >> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/app.js HTTP/1.1" 200 - >> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/style.css HTTP/1.1" 200 >> - >> Request: POST >> First name from form is {'{"foo":"C"}': ''} >> 127.0.0.1 - - [29/Jan/2018 16:40:16] "POST / HTTP/1.1" 200 - >> >> I'm not not quite sure why the key/value pair is embedded in a dictionary >> as the key with an empty value. >> >> Any pointers would be much appreciated! >> >> Thanks, >> >> -Clint >> >> > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kajocina at gmail.com Thu Feb 1 11:32:29 2018 From: kajocina at gmail.com (Piotr Grabowski) Date: Thu, 1 Feb 2018 17:32:29 +0100 Subject: [Flask] simple query testing of forms in Flask Message-ID: Hi there, I have a Flask application that is visualizing data based on queries that users make in a text form on the website. There is only a finite number of queries that can be made (~15.000). However, for technical reasons some queries sometimes fail, e.g. when a user misspells a query. In most cases everything is handled well but I do occasionally see some fringe cases that break the app and the users get a white screen. My question: is there some simple solution that could help me iterate over the list of possible queries (that I have) to check if they ever break the app? I can imagine that a bash script could do this and just list all cases which didn't return 200/OK from the server, but maybe there is a nicer way to do it? I already looked at http://flask.pocoo.org/docs/0.12/testing/ but have no experience with this and need some quick fix before I learn how to write proper Flask unit tests... I'll be thankful for any tips! Best, Piotr -------------- next part -------------- An HTML attachment was scrubbed... URL: From clint.olsen at gmail.com Thu Feb 1 12:42:46 2018 From: clint.olsen at gmail.com (Clint Olsen) Date: Thu, 1 Feb 2018 09:42:46 -0800 Subject: [Flask] Help with simple example using AngularJS In-Reply-To: References: Message-ID: Actually, you can't. Writing the code fragment you've shown results in an exception. The key in the immutable dict is actually a key *AND* value pair: ImmutableMultiDict([('{"nonstringify":"Cl","stringy":"foo"}', '')]) If I ask for the keys for this object, I get: ['{"first_name":"asdfasdf"}'] Which doesn't make sense to me how I get this extra level of indirection... Thanks, -Clint On Wed, Jan 31, 2018 at 9:22 PM, Gergely Polonkai wrote: > Hello, > > request.form is an ImmutableMultiDict. You can simply subscript it like > > first_name = request.form['first_name'] > > given the name of the HTML form field is first_name. No to_dict() or other > black magic is needed (well, not unless you have multiple fields with the > same name). > > Best, > Gergely > > On Thu, Feb 1, 2018, 01:19 Clint Olsen wrote: > >> Hi: >> >> I should probably add that before I tried messing around with decoding >> the form, I just blurted out the object on the receiving side and got: >> >> from flask import Flask, request, send_file >> >> app = Flask(__name__) >> >> @app.route('/', methods=['GET', 'POST']) >> def index(): >> print('Request: %s' % request.method) >> if request.method == 'POST': >> data = request.form #.to_dict() >> print('First name from form is %s' % data) >> return 'OK' >> else: >> return send_file("static/index.html") >> >> if __name__ == "__main__": >> app.run(host='0.0.0.0', debug=True) >> >> First name from form is ImmutableMultiDict([('{"non-stringify":"asdfasdf"}', >> '')]) >> >> So, even prior to attempt digging the info out of this structure I see >> the issue. >> >> Thanks, >> >> -Clint >> >> On Mon, Jan 29, 2018 at 4:52 PM, Clint Olsen >> wrote: >> >>> Hi: >>> >>> I'm new to Flask and Angular and only done a little web-based >>> programming, so please forgive my lack of understanding. I've just cobbled >>> together examples from Flask as well as some examples online to come up >>> with the following. >>> >>> I am interested in the most basic functionality of modifying a web form >>> and capturing that in the back-end to prove I can get data at least in one >>> direction: >>> >>> *static/app.js*: >>> >>> var app = angular.module('myApp', []); >>> >>> app.controller('formCtrl', function($scope, $log, $http) { >>> $scope.firstName = "John"; >>> >>> $scope.SendData = function () { >>> var data = { 'foo': $scope.firstName }; >>> >>> var config = { >>> headers : { >>> 'Content-Type': 'application/x-www-form- >>> urlencoded;charset=utf-8;' >>> } >>> } >>> >>> $http.post('/', data, config) >>> .success(function(results) { >>> $log.log(results); >>> }) >>> .error(function(error) { >>> $log.log(error); >>> }); >>> }; >>> }); >>> >>> *static/index.html*: >>> >>> >>> >>> >>> >>> >>> >>> >>> >>> >>>
>>>
>>> First Name: >>> >>> >>>
>>> >>>

You entered: {{firstName}}

>>> >>>
>>> >>> >>> >>> *app.py*: >>> >>> from flask import Flask, request, send_file >>> >>> app = Flask(__name__) >>> >>> @app.route('/', methods=['GET', 'POST']) >>> def index(): >>> print('Request: %s' % request.method) >>> if request.method == 'POST': >>> data = request.form.to_dict() >>> print('First name from form is %s' % data) >>> return 'OK' >>> else: >>> return send_file("static/index.html") >>> >>> if __name__ == "__main__": >>> app.run(host='0.0.0.0', debug=True) >>> >>> This code (sort of) works, but the message I get from index() is kind of >>> weird, so maybe I'm not packaging the data payload correctly? In this >>> example I just populate the form with a "C": >>> >>> Flask log: >>> >>> Request: GET >>> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /? HTTP/1.1" 200 - >>> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/app.js HTTP/1.1" 200 - >>> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/style.css HTTP/1.1" >>> 200 - >>> Request: POST >>> First name from form is {'{"foo":"C"}': ''} >>> 127.0.0.1 - - [29/Jan/2018 16:40:16] "POST / HTTP/1.1" 200 - >>> >>> I'm not not quite sure why the key/value pair is embedded in a >>> dictionary as the key with an empty value. >>> >>> Any pointers would be much appreciated! >>> >>> Thanks, >>> >>> -Clint >>> >>> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Thu Feb 1 12:45:51 2018 From: gergely at polonkai.eu (Gergely Polonkai) Date: Thu, 01 Feb 2018 17:45:51 +0000 Subject: [Flask] Help with simple example using AngularJS In-Reply-To: References: Message-ID: Yes, I see that, but my guess was that?s the result of JSON.Stringifying the form data. If not, it would help a lot if OP could check (eg. in the browser's development console) what is actually sent. On Thu, Feb 1, 2018, 18:42 Clint Olsen wrote: > Actually, you can't. Writing the code fragment you've shown results in an > exception. The key in the immutable dict is actually a key *AND* value > pair: > > ImmutableMultiDict([('{"nonstringify":"Cl","stringy":"foo"}', '')]) > > If I ask for the keys for this object, I get: > > ['{"first_name":"asdfasdf"}'] > > Which doesn't make sense to me how I get this extra level of indirection... > > Thanks, > > -Clint > > > > On Wed, Jan 31, 2018 at 9:22 PM, Gergely Polonkai > wrote: > >> Hello, >> >> request.form is an ImmutableMultiDict. You can simply subscript it like >> >> first_name = request.form['first_name'] >> >> given the name of the HTML form field is first_name. No to_dict() or >> other black magic is needed (well, not unless you have multiple fields with >> the same name). >> >> Best, >> Gergely >> >> On Thu, Feb 1, 2018, 01:19 Clint Olsen wrote: >> >>> Hi: >>> >>> I should probably add that before I tried messing around with decoding >>> the form, I just blurted out the object on the receiving side and got: >>> >>> from flask import Flask, request, send_file >>> >>> app = Flask(__name__) >>> >>> @app.route('/', methods=['GET', 'POST']) >>> def index(): >>> print('Request: %s' % request.method) >>> if request.method == 'POST': >>> data = request.form #.to_dict() >>> print('First name from form is %s' % data) >>> return 'OK' >>> else: >>> return send_file("static/index.html") >>> >>> if __name__ == "__main__": >>> app.run(host='0.0.0.0', debug=True) >>> >>> First name from form is >>> ImmutableMultiDict([('{"non-stringify":"asdfasdf"}', '')]) >>> >>> So, even prior to attempt digging the info out of this structure I see >>> the issue. >>> >>> Thanks, >>> >>> -Clint >>> >>> On Mon, Jan 29, 2018 at 4:52 PM, Clint Olsen >>> wrote: >>> >>>> Hi: >>>> >>>> I'm new to Flask and Angular and only done a little web-based >>>> programming, so please forgive my lack of understanding. I've just cobbled >>>> together examples from Flask as well as some examples online to come up >>>> with the following. >>>> >>>> I am interested in the most basic functionality of modifying a web form >>>> and capturing that in the back-end to prove I can get data at least in one >>>> direction: >>>> >>>> *static/app.js*: >>>> >>>> var app = angular.module('myApp', []); >>>> >>>> app.controller('formCtrl', function($scope, $log, $http) { >>>> $scope.firstName = "John"; >>>> >>>> $scope.SendData = function () { >>>> var data = { 'foo': $scope.firstName }; >>>> >>>> var config = { >>>> headers : { >>>> 'Content-Type': >>>> 'application/x-www-form-urlencoded;charset=utf-8;' >>>> } >>>> } >>>> >>>> $http.post('/', data, config) >>>> .success(function(results) { >>>> $log.log(results); >>>> }) >>>> .error(function(error) { >>>> $log.log(error); >>>> }); >>>> }; >>>> }); >>>> >>>> *static/index.html*: >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>> >>>>
>>>>
>>>> First Name: >>>> >>>> >>>>
>>>> >>>>

You entered: {{firstName}}

>>>> >>>>
>>>> >>>> >>>> >>>> *app.py*: >>>> >>>> from flask import Flask, request, send_file >>>> >>>> app = Flask(__name__) >>>> >>>> @app.route('/', methods=['GET', 'POST']) >>>> def index(): >>>> print('Request: %s' % request.method) >>>> if request.method == 'POST': >>>> data = request.form.to_dict() >>>> print('First name from form is %s' % data) >>>> return 'OK' >>>> else: >>>> return send_file("static/index.html") >>>> >>>> if __name__ == "__main__": >>>> app.run(host='0.0.0.0', debug=True) >>>> >>>> This code (sort of) works, but the message I get from index() is kind >>>> of weird, so maybe I'm not packaging the data payload correctly? In this >>>> example I just populate the form with a "C": >>>> >>>> Flask log: >>>> >>>> Request: GET >>>> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /? HTTP/1.1" 200 - >>>> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/app.js HTTP/1.1" 200 - >>>> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/style.css HTTP/1.1" >>>> 200 - >>>> Request: POST >>>> First name from form is {'{"foo":"C"}': ''} >>>> 127.0.0.1 - - [29/Jan/2018 16:40:16] "POST / HTTP/1.1" 200 - >>>> >>>> I'm not not quite sure why the key/value pair is embedded in a >>>> dictionary as the key with an empty value. >>>> >>>> Any pointers would be much appreciated! >>>> >>>> Thanks, >>>> >>>> -Clint >>>> >>>> >>> _______________________________________________ >>> Flask mailing list >>> Flask at python.org >>> https://mail.python.org/mailman/listinfo/flask >>> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From clint.olsen at gmail.com Thu Feb 1 12:51:47 2018 From: clint.olsen at gmail.com (Clint Olsen) Date: Thu, 1 Feb 2018 09:51:47 -0800 Subject: [Flask] Help with simple example using AngularJS In-Reply-To: References: Message-ID: When I got the exception, I do see the following in the browser console: Possibly unhandled rejection: {"data":"\n400 Bad Request\n

Bad Request

\n

The browser (or proxy) sent a request that this server could not understand.

\n","status":400,"config":{"method":"POST","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","headers":{"Content-Type":"application/x-www-form-urlencoded","Accept":"application/json, text/plain, */*"},"url":"/","data":{"first_name":"asdfaasdfasdf"}},"statusText":"BAD REQUEST","xhrStatus":"complete"} This would imply that the JS code is sending a sensible JSON fragment, correct? -Clint On Thu, Feb 1, 2018 at 9:45 AM, Gergely Polonkai wrote: > Yes, I see that, but my guess was that?s the result of JSON.Stringifying > the form data. > > If not, it would help a lot if OP could check (eg. in the browser's > development console) what is actually sent. > > On Thu, Feb 1, 2018, 18:42 Clint Olsen wrote: > >> Actually, you can't. Writing the code fragment you've shown results in an >> exception. The key in the immutable dict is actually a key *AND* value >> pair: >> >> ImmutableMultiDict([('{"nonstringify":"Cl","stringy":"foo"}', '')]) >> >> If I ask for the keys for this object, I get: >> >> ['{"first_name":"asdfasdf"}'] >> >> Which doesn't make sense to me how I get this extra level of >> indirection... >> >> Thanks, >> >> -Clint >> >> >> >> On Wed, Jan 31, 2018 at 9:22 PM, Gergely Polonkai >> wrote: >> >>> Hello, >>> >>> request.form is an ImmutableMultiDict. You can simply subscript it like >>> >>> first_name = request.form['first_name'] >>> >>> given the name of the HTML form field is first_name. No to_dict() or >>> other black magic is needed (well, not unless you have multiple fields with >>> the same name). >>> >>> Best, >>> Gergely >>> >>> On Thu, Feb 1, 2018, 01:19 Clint Olsen wrote: >>> >>>> Hi: >>>> >>>> I should probably add that before I tried messing around with decoding >>>> the form, I just blurted out the object on the receiving side and got: >>>> >>>> from flask import Flask, request, send_file >>>> >>>> app = Flask(__name__) >>>> >>>> @app.route('/', methods=['GET', 'POST']) >>>> def index(): >>>> print('Request: %s' % request.method) >>>> if request.method == 'POST': >>>> data = request.form #.to_dict() >>>> print('First name from form is %s' % data) >>>> return 'OK' >>>> else: >>>> return send_file("static/index.html") >>>> >>>> if __name__ == "__main__": >>>> app.run(host='0.0.0.0', debug=True) >>>> >>>> First name from form is ImmutableMultiDict([('{"non-stringify":"asdfasdf"}', >>>> '')]) >>>> >>>> So, even prior to attempt digging the info out of this structure I see >>>> the issue. >>>> >>>> Thanks, >>>> >>>> -Clint >>>> >>>> On Mon, Jan 29, 2018 at 4:52 PM, Clint Olsen >>>> wrote: >>>> >>>>> Hi: >>>>> >>>>> I'm new to Flask and Angular and only done a little web-based >>>>> programming, so please forgive my lack of understanding. I've just cobbled >>>>> together examples from Flask as well as some examples online to come up >>>>> with the following. >>>>> >>>>> I am interested in the most basic functionality of modifying a web >>>>> form and capturing that in the back-end to prove I can get data at least in >>>>> one direction: >>>>> >>>>> *static/app.js*: >>>>> >>>>> var app = angular.module('myApp', []); >>>>> >>>>> app.controller('formCtrl', function($scope, $log, $http) { >>>>> $scope.firstName = "John"; >>>>> >>>>> $scope.SendData = function () { >>>>> var data = { 'foo': $scope.firstName }; >>>>> >>>>> var config = { >>>>> headers : { >>>>> 'Content-Type': 'application/x-www-form- >>>>> urlencoded;charset=utf-8;' >>>>> } >>>>> } >>>>> >>>>> $http.post('/', data, config) >>>>> .success(function(results) { >>>>> $log.log(results); >>>>> }) >>>>> .error(function(error) { >>>>> $log.log(error); >>>>> }); >>>>> }; >>>>> }); >>>>> >>>>> *static/index.html*: >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>
>>>>>
>>>>> First Name: >>>>> >>>>> >>>>>
>>>>> >>>>>

You entered: {{firstName}}

>>>>> >>>>>
>>>>> >>>>> >>>>> >>>>> *app.py*: >>>>> >>>>> from flask import Flask, request, send_file >>>>> >>>>> app = Flask(__name__) >>>>> >>>>> @app.route('/', methods=['GET', 'POST']) >>>>> def index(): >>>>> print('Request: %s' % request.method) >>>>> if request.method == 'POST': >>>>> data = request.form.to_dict() >>>>> print('First name from form is %s' % data) >>>>> return 'OK' >>>>> else: >>>>> return send_file("static/index.html") >>>>> >>>>> if __name__ == "__main__": >>>>> app.run(host='0.0.0.0', debug=True) >>>>> >>>>> This code (sort of) works, but the message I get from index() is kind >>>>> of weird, so maybe I'm not packaging the data payload correctly? In this >>>>> example I just populate the form with a "C": >>>>> >>>>> Flask log: >>>>> >>>>> Request: GET >>>>> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /? HTTP/1.1" 200 - >>>>> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/app.js HTTP/1.1" 200 >>>>> - >>>>> 127.0.0.1 - - [29/Jan/2018 16:40:11] "GET /static/style.css HTTP/1.1" >>>>> 200 - >>>>> Request: POST >>>>> First name from form is {'{"foo":"C"}': ''} >>>>> 127.0.0.1 - - [29/Jan/2018 16:40:16] "POST / HTTP/1.1" 200 - >>>>> >>>>> I'm not not quite sure why the key/value pair is embedded in a >>>>> dictionary as the key with an empty value. >>>>> >>>>> Any pointers would be much appreciated! >>>>> >>>>> Thanks, >>>>> >>>>> -Clint >>>>> >>>>> >>>> _______________________________________________ >>>> Flask mailing list >>>> Flask at python.org >>>> https://mail.python.org/mailman/listinfo/flask >>>> >>> >> -------------- next part -------------- An HTML attachment was scrubbed... URL: From vladimirbright at gmail.com Thu Feb 1 13:39:23 2018 From: vladimirbright at gmail.com (Vladimir Prokhoda) Date: Thu, 1 Feb 2018 21:39:23 +0300 Subject: [Flask] simple query testing of forms in Flask In-Reply-To: References: Message-ID: Hi Piotr, take a look at https://docs.sentry.io/clients/python/integrations/flask/ . It's rock solid service for tracking 500 responses from python web applications. I think you will easily detect queries that breaks your app. On Thu, Feb 1, 2018 at 7:32 PM, Piotr Grabowski wrote: > Hi there, > > I have a Flask application that is visualizing data based on queries that > users make in a text form on the website. There is only a finite number of > queries that can be made (~15.000). However, for technical reasons some > queries sometimes fail, e.g. when a user misspells a query. > > In most cases everything is handled well but I do occasionally see some > fringe cases that break the app and the users get a white screen. > > My question: is there some simple solution that could help me iterate over > the list of possible queries (that I have) to check if they ever break the > app? I can imagine that a bash script could do this and just list all cases > which didn't return 200/OK from the server, but maybe there is a nicer way > to do it? > > I already looked at http://flask.pocoo.org/docs/0.12/testing/ but have no > experience with this and need some quick fix before I learn how to write > proper Flask unit tests... > > I'll be thankful for any tips! > > Best, > Piotr > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -- ???? ???? ??????? ????, ???????? ??? ??????: ?? ?????? ????? ?????? ???????. -------------- next part -------------- An HTML attachment was scrubbed... URL: From kajocina at gmail.com Fri Feb 2 04:52:37 2018 From: kajocina at gmail.com (Piotr Grabowski) Date: Fri, 2 Feb 2018 10:52:37 +0100 Subject: [Flask] simple query testing of forms in Flask In-Reply-To: References: Message-ID: Thanks Vladimir! I am already using Sentry (and I love it, I highly recommend it to anyone running Flask web apps). However, I wanted to take a proactive approach here and check before the users learn the "hard way". Maybe indeed the only way is to set up unit tests and check if returned response by the app is correct. If anyone has more ideas, I will be happy to hear them! Best, Piotr On Thu, Feb 1, 2018 at 7:39 PM, Vladimir Prokhoda wrote: > Hi Piotr, > > take a look at https://docs.sentry.io/clients/python/integrations/flask/ > . It's rock solid service for tracking 500 responses from python web > applications. I think you will easily detect queries that breaks your app. > > On Thu, Feb 1, 2018 at 7:32 PM, Piotr Grabowski > wrote: > >> Hi there, >> >> I have a Flask application that is visualizing data based on queries that >> users make in a text form on the website. There is only a finite number of >> queries that can be made (~15.000). However, for technical reasons some >> queries sometimes fail, e.g. when a user misspells a query. >> >> In most cases everything is handled well but I do occasionally see some >> fringe cases that break the app and the users get a white screen. >> >> My question: is there some simple solution that could help me iterate >> over the list of possible queries (that I have) to check if they ever break >> the app? I can imagine that a bash script could do this and just list all >> cases which didn't return 200/OK from the server, but maybe there is a >> nicer way to do it? >> >> I already looked at http://flask.pocoo.org/docs/0.12/testing/ but have >> no experience with this and need some quick fix before I learn how to write >> proper Flask unit tests... >> >> I'll be thankful for any tips! >> >> Best, >> Piotr >> >> _______________________________________________ >> Flask mailing list >> Flask at python.org >> https://mail.python.org/mailman/listinfo/flask >> >> > > > -- > ???? ???? ??????? ????, ???????? ??? ??????: ?? ?????? ????? ?????? > ???????. > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ish at lsl.digital Sun Feb 11 13:55:20 2018 From: ish at lsl.digital (Ish Sookun) Date: Sun, 11 Feb 2018 22:55:20 +0400 Subject: [Flask] Flask v0.12 documentation PDF Message-ID: Hello, The link [1] to the PDF version of the Flask 0.12 documentation on the homepage is broken. It returns a 404 error. Regards, Ish Sookun [1] http://flask.pocoo.org/docs/0.12/.latex/Flask.pdf From gergely at polonkai.eu Sun Feb 11 14:27:17 2018 From: gergely at polonkai.eu (Gergely Polonkai) Date: Sun, 11 Feb 2018 19:27:17 +0000 Subject: [Flask] Registering Flask-SQLAlchemy models from an extension Message-ID: Hello, I want to create an extension that, among other things, defines ORM models. Being an extension, this means it is not me who defines the flask_sqlalchemy.SQLAlchemy object, so I can?t write my model classes like class MyModel(db.Model): Is there a recipe for this scenario? Thanks in advance, Gergely -------------- next part -------------- An HTML attachment was scrubbed... URL: From david at davidbaumgold.com Sun Feb 11 16:30:21 2018 From: david at davidbaumgold.com (David Baumgold) Date: Sun, 11 Feb 2018 22:30:21 +0100 Subject: [Flask] Registering Flask-SQLAlchemy models from an extension In-Reply-To: References: Message-ID: I?m the maintainer of Flask-Dance, and my extension has to deal with this problem, too. I decided to solve it by providing a mixin class, and directing developers to define their own ORM model by inheriting from that mixin class. Then, the developer must pass the defined ORM model back to a class I defined, that knows how to handle it. Here?s the relevant documentation for my Flask extension:?https://flask-dance.readthedocs.io/en/latest/backends.html#sqlalchemy And here?s the docs for SQLAlchemy mixins:?http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/mixins.html Does that help? David Baumgold On February 11, 2018 at 8:27:42 PM, Gergely Polonkai (gergely at polonkai.eu) wrote: Hello, I want to create an extension that, among other things, defines ORM models. Being an extension, this means it is not me who defines the flask_sqlalchemy.SQLAlchemy object, so I can?t write my model classes like class MyModel(db.Model): Is there a recipe for this scenario? Thanks in advance, Gergely? _______________________________________________ Flask mailing list Flask at python.org https://mail.python.org/mailman/listinfo/flask -------------- next part -------------- An HTML attachment was scrubbed... URL: From gergely at polonkai.eu Mon Feb 12 00:09:24 2018 From: gergely at polonkai.eu (Gergely Polonkai) Date: Mon, 12 Feb 2018 05:09:24 +0000 Subject: [Flask] Registering Flask-SQLAlchemy models from an extension In-Reply-To: References: Message-ID: That?s exactly how Flask-Login works (that extension is not even aware of the database). I considered this path, too, and will probably go with that, as it lets the developer choose how to persist data, and won?t bind them to one specific solution. However, I?m still interested in a solution to the original problem, so if anyone knows it, don?t hesitate to reply :) Best, Gergely On Sun, Feb 11, 2018, 22:30 David Baumgold wrote: > I?m the maintainer of Flask-Dance, and my extension has to deal with this > problem, too. I decided to solve it by providing a mixin class, and > directing developers to define their own ORM model by inheriting from that > mixin class. Then, the developer must pass the defined ORM model back to a > class I defined, that knows how to handle it. > > Here?s the relevant documentation for my Flask extension: > https://flask-dance.readthedocs.io/en/latest/backends.html#sqlalchemy > And here?s the docs for SQLAlchemy mixins: > http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/mixins.html > > Does that help? > > David Baumgold > > > On February 11, 2018 at 8:27:42 PM, Gergely Polonkai (gergely at polonkai.eu) > wrote: > > Hello, > > I want to create an extension that, among other things, defines ORM > models. Being an extension, this means it is not me who defines the > flask_sqlalchemy.SQLAlchemy object, so I can?t write my model classes like > > class MyModel(db.Model): > > Is there a recipe for this scenario? > > Thanks in advance, > Gergely > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From spaceman at antispaceman.com Fri Feb 16 07:42:59 2018 From: spaceman at antispaceman.com (spaceman) Date: Fri, 16 Feb 2018 12:42:59 +0000 Subject: [Flask] Flask-Login and Flask-Session Message-ID: <20180216124259.C79658B6@home.antispaceman.com> I wonder if anyone can help me as my knowledge of python isn't good enough figure this out: I am using Flask-Session with the RedisSessionInterface (works by itself) but I also trying to use Flask-Login with a custom session interface as specified here: https://flask-login.readthedocs.io/en/latest/#disabling-session-cookie-for-apis I am pretty certain the code specified there won't work with the RedisSessionInterface as it is using flask's default session interface. I tried this: class CustomSessionInterface(RedisSessionInterface): """Prevent creating session from API requests.""" def save_session(self, *args, **kwargs): if g.get('login_via_header'): return return super(CustomSessionInterface, self).save_session(*args, **kwargs) But the RedisSessionInterface requires arguments (three to be exact) to configure it properly. My initialization looks like: ... from flask_login import LoginManager from flask_redis import Redis from flask_session import Session, RedisSessionInterface ... redis.init_app(app) app.config['SESSION_REDIS'] = app.extensions['redis']['REDIS'] session.init_app(app) app.session_interface = CustomSessionInterface() login_manager.init_app(app) ... I need to take the session interface that initialized by Flask-Session and turn it into a CustomSessionInterface with the login_via_header set so that my api won't return a session cookie but still use the RedisSessionInterface, and my simple brain can't do that. Regards, spaceman From spaceman at antispaceman.com Fri Feb 16 09:08:53 2018 From: spaceman at antispaceman.com (spaceman) Date: Fri, 16 Feb 2018 14:08:53 +0000 Subject: [Flask] Flask-Login and Flask-Session In-Reply-To: <20180216124259.C79658B6@home.antispaceman.com> References: <20180216124259.C79658B6@home.antispaceman.com> Message-ID: <20180216140853.B26658B6@home.antispaceman.com> Figured this out for myself: > But the RedisSessionInterface requires arguments (three to be exact) > to configure it properly. My initialization looks like: just decided provide the variables myself like so: app.session_interface = CustomSessionInterface(None, '', None) using the CustomSessionInterface. Regards, spaceman From riteshn at gmail.com Mon Feb 19 01:41:01 2018 From: riteshn at gmail.com (Ritesh Nadhani) Date: Sun, 18 Feb 2018 22:41:01 -0800 Subject: [Flask] Prometheus monitoring/statistics Message-ID: Hello What library for sending metrics to Prometheus is being used by folks here. There is a plugin flask-prometheus but it seems it has issues (which I am also facing) when using with multi-process uwsgi setup: https://github.com/sbarratt/flask-prometheus/issues/3 (the issue related to gunicorn but its the same issue) -- Ritesh