From ar at zeit.io Fri May 3 14:58:38 2019 From: ar at zeit.io (Arup Rakshit) Date: Sat, 4 May 2019 00:28:38 +0530 Subject: [Flask] Shouldn't is and == operator work same way while doing string comparisons? Message-ID: <25DDD2C0-4ECA-4299-AFF0-4A64C51EADE6@zeit.io> Hi, I am facing a problem with `is` and `==` comparisons. The small below program gives different outputs. When I use `if book['isbn'] is isbn]` I get an empty output, but `if book['isbn'] == isbn]` gives correct output. Why it is like that? from flask import Flask, jsonify app = Flask(__name__) books = [ { "name": 'Learning Python', 'isbn': '1449355730', 'price': 200 }, { "name": 'Practical Object-Oriented Design: An Agile Primer Using Ruby', 'isbn': 'B07F88LY9M', 'price': 210 } ] # ?. @app.route('/books/') def get_book_by_isbn(isbn): return jsonify([{'name': book['name'], 'price': book['price']} for book in books if book['isbn'] == isbn]) if __name__ == "__main__": app.run(debug=True) Curl program: ~$ curl http://127.0.0.1:5000/books/B07F88LY9M [] ~$ curl http://127.0.0.1:5000/books/B07F88LY9M [ { "name": "Practical Object-Oriented Design: An Agile Primer Using Ruby", "price": 210 } ] Thanks, Arup Rakshit ar at zeit.io From ar at zeit.io Fri May 3 15:11:58 2019 From: ar at zeit.io (Arup Rakshit) Date: Sat, 4 May 2019 00:41:58 +0530 Subject: [Flask] Shouldn't is and == operator work same way while doing string comparisons? In-Reply-To: References: <25DDD2C0-4ECA-4299-AFF0-4A64C51EADE6@zeit.io> Message-ID: <9E9261F1-E2E8-44B0-8F12-6D0F0DE4F33A@zeit.io> Hello Josh, I tested the both while in REPL. They work same, why it is then different then flask app code? Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> books = [ ... { ... "name": 'Learning Python', ... 'isbn': '1449355730', ... 'price': 200 ... }, ... { ... "name": 'Practical Object-Oriented Design: An Agile Primer Using Ruby', ... 'isbn': 'B07F88LY9M', ... 'price': 210 ... } ... ] >>> [{'name': book['name'], 'price': book['price']} for book in books if book['isbn'] is 'B07F88LY9M'] [{'name': 'Practical Object-Oriented Design: An Agile Primer Using Ruby', 'price': 210}] >>> [{'name': book['name'], 'price': book['price']} for book in books if book['isbn'] == 'B07F88LY9M'] [{'name': 'Practical Object-Oriented Design: An Agile Primer Using Ruby', 'price': 210}] >>> isbn = 'B07F88LY9M' >>> [{'name': book['name'], 'price': book['price']} for book in books if book['isbn'] == isbn] [{'name': 'Practical Object-Oriented Design: An Agile Primer Using Ruby', 'price': 210}] >>> [{'name': book['name'], 'price': book['price']} for book in books if book['isbn'] is isbn] [{'name': 'Practical Object-Oriented Design: An Agile Primer Using Ruby', 'price': 210}] Thanks, Arup Rakshit ar at zeit.io > On 04-May-2019, at 12:35 AM, Josh Morrow wrote: > > https://stackoverflow.com/questions/132988/is-there-a-difference-between-and-is > > On Fri, May 3, 2019 at 11:59 AM Arup Rakshit wrote: > Hi, > > I am facing a problem with `is` and `==` comparisons. The small below program gives different outputs. When I use `if book['isbn'] is isbn]` I get an empty output, but `if book['isbn'] == isbn]` gives correct output. Why it is like that? > > from flask import Flask, jsonify > > app = Flask(__name__) > > books = [ > { > "name": 'Learning Python', > 'isbn': '1449355730', > 'price': 200 > }, > { > "name": 'Practical Object-Oriented Design: An Agile Primer Using Ruby', > 'isbn': 'B07F88LY9M', > 'price': 210 > } > ] > > > # ?. > > @app.route('/books/') > def get_book_by_isbn(isbn): > return jsonify([{'name': book['name'], 'price': book['price']} for book in books if book['isbn'] == isbn]) > > > if __name__ == "__main__": > app.run(debug=True) > > > Curl program: > > ~$ curl http://127.0.0.1:5000/books/B07F88LY9M > [] > ~$ curl http://127.0.0.1:5000/books/B07F88LY9M > [ > { > "name": "Practical Object-Oriented Design: An Agile Primer Using Ruby", > "price": 210 > } > ] > > > Thanks, > > Arup Rakshit > ar at zeit.io > > > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask From ar at zeit.io Fri May 3 15:23:46 2019 From: ar at zeit.io (Arup Rakshit) Date: Sat, 4 May 2019 00:53:46 +0530 Subject: [Flask] flask-couchdb maintainers are around? Message-ID: I am recently messing around with Flask and couchDB. I used the package https://pythonhosted.org/Flask-CouchDB/#basic-use . But my program kept giving errors, which later fixed by someone from Reddit https://www.reddit.com/r/flask/comments/bk5g3w/python_flaskcouchdb_attributeerror_appctxglobals/emf6tyq/ . I followed what that Reddit guy said, and I met another problem https://www.reddit.com/r/flask/comments/bk5g3w/python_flaskcouchdb_attributeerror_appctxglobals/emfc6fl. Now he told me that it is related to incompatibility between python2 and python3 as per the PR https://bitbucket.org/leafstorm/flask-couchdb/pull-requests/2/fix-python-3-incompatibility/diff . If maintainers are around would you mind to take a look at the project, and merge the PR. There is no other option I found to use couchdb with flask except this ORM. Thanks, Arup Rakshit ar at zeit.io From cs at cskk.id.au Fri May 3 19:29:58 2019 From: cs at cskk.id.au (Cameron Simpson) Date: Sat, 4 May 2019 09:29:58 +1000 Subject: [Flask] Shouldn't is and == operator work same way while doing string comparisons? In-Reply-To: <9E9261F1-E2E8-44B0-8F12-6D0F0DE4F33A@zeit.io> References: <9E9261F1-E2E8-44B0-8F12-6D0F0DE4F33A@zeit.io> Message-ID: <20190503232958.GA2976@cskk.homeip.net> On 04May2019 00:41, Arup Rakshit wrote: >I tested the both while in REPL. Testing only tells you what happens in your test, with a aprticular environment. It doesn't inform you about the language specification, except in so far as a failed test might tell you that your assumption was incorrect. >They work same, why it is then different then flask app code? Python interning small strings is an implementation detail, not part of the language specification. So there is no explicit guarantee that 2 strings with the same value are the same string object, even for small strings. If you want to act on the value of something, use ==. Using "is" is NOT FOR THAT. It is to check if 2 object references refer to the same object. This is rarely what you want; it is most useful with singletons such as sentinels. Cheers, Cameron Simpson From gergely at polonkai.eu Sat May 4 01:10:46 2019 From: gergely at polonkai.eu (Gergely Polonkai) Date: Sat, 4 May 2019 07:10:46 +0200 Subject: [Flask] Shouldn't is and == operator work same way while doing string comparisons? In-Reply-To: <20190503232958.GA2976@cskk.homeip.net> References: <9E9261F1-E2E8-44B0-8F12-6D0F0DE4F33A@zeit.io> <20190503232958.GA2976@cskk.homeip.net> Message-ID: ?in fact, i can easily give OP a counterexample with strings: >>> a = 'hello' + ' world' >>> b = 'hello world' >>> a 'hello world' >>> b 'hello world' >>> a == b True >>> a is b False Gergely Polonkai [image: https://]about.me/gergely.polonkai lau., 4. ma? 2019 kl. 01:30 skrifa?i Cameron Simpson : > On 04May2019 00:41, Arup Rakshit wrote: > >I tested the both while in REPL. > > Testing only tells you what happens in your test, with a aprticular > environment. It doesn't inform you about the language specification, > except in so far as a failed test might tell you that your assumption > was incorrect. > > >They work same, why it is then different then flask app code? > > Python interning small strings is an implementation detail, not part of > the language specification. So there is no explicit guarantee that 2 > strings with the same value are the same string object, even for small > strings. > > If you want to act on the value of something, use ==. Using "is" is NOT > FOR THAT. It is to check if 2 object references refer to the same > object. This is rarely what you want; it is most useful with singletons > such as sentinels. > > Cheers, > Cameron Simpson > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From tim at akwebsoft.com Sun May 5 20:54:50 2019 From: tim at akwebsoft.com (Tim Johnson) Date: Sun, 5 May 2019 16:54:50 -0800 Subject: [Flask] Shouldn't is and == operator work same way while doing string comparisons? In-Reply-To: References: <9E9261F1-E2E8-44B0-8F12-6D0F0DE4F33A@zeit.io> <20190503232958.GA2976@cskk.homeip.net> Message-ID: <20190506005450.GJ2404@mail.akwebsoft.com> * Gergely Polonkai [190503 21:20]: > ?in fact, i can easily give OP a counterexample with strings: > > >>> a = 'hello' + ' world' > >>> b = 'hello world' > >>> a > 'hello world' > >>> b > 'hello world' > >>> a == b > True > >>> a is b > False > > > > Gergely Polonkai > [image: https://]about.me/gergely.polonkai > Another way of looking at what Gergely puts it is that variables a and b may contain equal contents but they have different addresses in memory. They are in fact NOT the same object -- Tim Johnson http://www.tj49.com From skip.montanaro at gmail.com Tue May 7 14:48:25 2019 From: skip.montanaro at gmail.com (Skip Montanaro) Date: Tue, 7 May 2019 13:48:25 -0500 Subject: [Flask] Getting a timestamp column wrong for an existing database table Message-ID: I'm trying to model an existing SQL Server table. It has a stamp column of type datetime. I tried declaring it like so: class Summary(DB.Model): ... stamp = DB.Column(DB.TIMESTAMP) ... When I start my Flask server, it complains: Attribute 'stamp' on class appears to be a non-schema 'sqlalchemy.sql.column()' object; this won't be part of the declarative mapping I've tried the following, all to no avail: * DB.Column(DB.DATETIME) * Changed the column in the database from datetime to datetime2 * DB.Column(SMALLDATETIME), where that comes from sqlalchemy.dialects.mssql. How do I deal with this? I'm currently unable to use stamp as a query constraint (at least I think so). Skip Montanaro From arunim29 at gmail.com Mon May 13 05:36:40 2019 From: arunim29 at gmail.com (Arunim Chopra) Date: Mon, 13 May 2019 15:06:40 +0530 Subject: [Flask] Python 2.6.9 with Flask 1.0.2 Message-ID: Hi, I need to work with python 2.6.9 . I wanted to know what will break if I use Flask 1.0.2 with python 2.6.9 as it is no longer supported with this Flask version. Or is it better to use Flask 0.12 with python 2.6.9 Regards, Arunim Chopra -------------- next part -------------- An HTML attachment was scrubbed... URL: From lists at localguru.de Tue May 21 06:42:40 2019 From: lists at localguru.de (Marcus Schopen) Date: Tue, 21 May 2019 12:42:40 +0200 Subject: [Flask] get environment variables from mod_shib Message-ID: Hi, I'm using mod_shib for authentication and run my flask app via wsgi. How do I securely access to shib attributes like "uid" or "displayName" in my app? If I understood it correctly, it is insecure to pass the attributes with RequestHeader and read them in Flask with request.environ.get. Ciao Marcus From lists at localguru.de Tue May 21 07:56:20 2019 From: lists at localguru.de (Marcus Schopen) Date: Tue, 21 May 2019 13:56:20 +0200 Subject: [Flask] get environment variables from mod_shib In-Reply-To: References: Message-ID: <7c29a3af2369d670256a24a16579c1e6f28c2142.camel@localguru.de> Am Dienstag, den 21.05.2019, 12:42 +0200 schrieb Marcus Schopen: > Hi, > > I'm using mod_shib for authentication and run my flask app via wsgi. > How do I securely access to shib attributes like "uid" or > "displayName" > in my app? If I understood it correctly, it is insecure to pass the > attributes with RequestHeader and read them in Flask with > request.environ.get. This seems to work: request.environ['displayName'] Is there a further spoof checking necessary? Ciao Marcus From coreybrett at gmail.com Sat May 25 09:50:39 2019 From: coreybrett at gmail.com (Corey Boyle) Date: Sat, 25 May 2019 09:50:39 -0400 Subject: [Flask] Uwsgi emperor socket creation permissions Message-ID: So I am trying to setup Uwsgi / Emperor for multiple apps each running under their own user account. I have the Emperor running as root in tyrant mode, and it's starting the vassels and running them with their own accounts. The trouble I have is the permissions on the sockets created by the vassels. If I set chmod-socket = 666 everything works fine. The socket is created with the vassels user and group, but Nginx (and everyone else) is able to read/write because of the world permissions. I just don't think that's a good situation. What I can't figure out is how to have the vassels create the sockit with permissions that will allow the appuser(uwsgi) and Nginx to read/write, but keep everyone else out. I tried using chown-socket = appuser:www-data, but that doesn't work because appuser is not a member of the www-data group and therefore can't set is as group. Any suggestions? From coreybrett at gmail.com Sat May 25 12:10:48 2019 From: coreybrett at gmail.com (Corey Boyle) Date: Sat, 25 May 2019 12:10:48 -0400 Subject: [Flask] Uwsgi emperor socket creation permissions In-Reply-To: References: Message-ID: Thank you for the suggestion. I've read that the uwsgi binary protocol via a Unix sockit is more efficient than HTTP. So I'd like to have my cake and eat it too. ;-) HTTP may be my fallback plan if I can't figure this out. On Sat, May 25, 2019 at 11:52 AM Rodrigo Ram?rez Norambuena < decipher.hk at gmail.com> wrote: > On Sat, May 25, 2019 at 9:51 AM Corey Boyle wrote: > > > > [...] > > > > I tried using chown-socket = appuser:www-data, but that doesn't work > > because appuser is not a member of the www-data group and therefore > > can't set is as group. > > > > > > Any suggestions? > > You could running a wsgi process in http mode and Nginx get from this > backend as proxy pass. > > Here a little example: > > [uwsgi] > socket= 0.0.0.0:5000 > protocol=http > master = true > venv = /usr/local/apps/qpanel/env > chdir = /usr/local/apps/qpanel > mount = /qpanel=start.wsgi > manage-script-name = true > uid = x > gid = x > plugins = python > > Nginx > location /qpanel { > > proxy_pass http://localhost:5000/qpanel; > proxy_set_header Host $host; > proxy_set_header X-Real-IP $remote_addr; > > } > Regards! > -- > Rodrigo Ram?rez Norambuena > http://www.rodrigoramirez.com/ > -------------- next part -------------- An HTML attachment was scrubbed... URL: From decipher.hk at gmail.com Sat May 25 17:08:50 2019 From: decipher.hk at gmail.com (=?UTF-8?Q?Rodrigo_Ram=C3=ADrez_Norambuena?=) Date: Sat, 25 May 2019 17:08:50 -0400 Subject: [Flask] Uwsgi emperor socket creation permissions In-Reply-To: References: Message-ID: On Sat, May 25, 2019 at 12:11 PM Corey Boyle wrote: > > Thank you for the suggestion. I've read that the uwsgi binary protocol via a Unix sockit is more efficient than HTTP. So I'd like to have my cake and eat it too. ;-) HTTP may be my fallback plan if I can't figure this out. > Should be more efficient...but really need the extra performance? For this point, the uwsgi.ini file should be came a same permission user:group. I remember having a problem in Centos 7 for this situation. If run for the normal users system you can move the socket another places, example /var/run/.... with the Nginx user/group names permission. Or add the users in a group for uwsgi where www-data be part of this group too So, if you can share some information about your environment system (O.S.), Python Version, some configuration could be help to take a look Regards! -- Rodrigo Ram?rez Norambuena http://www.rodrigoramirez.com/ From coreybrett at gmail.com Sun May 26 10:11:40 2019 From: coreybrett at gmail.com (Corey Boyle) Date: Sun, 26 May 2019 10:11:40 -0400 Subject: [Flask] Uwsgi emperor socket creation permissions In-Reply-To: References: Message-ID: Took me some experimentation, but found something that appears to work. I created a new group and made appuser and www-data members. Then I tried using "chown-socket=appuser:newgroup", but that didn't work and made the Emperor curse the vassel. I had to change the ownership of the vassel's ini file to appuser:newgroup, and that did the trick. I am using "chmod-socket=660" in the ini, and that seems to work fine. Having to create the special group seems like an extra step, but I guess that could be automated. On Sat, May 25, 2019 at 5:09 PM Rodrigo Ram?rez Norambuena wrote: > > On Sat, May 25, 2019 at 12:11 PM Corey Boyle wrote: > > > > Thank you for the suggestion. I've read that the uwsgi binary protocol via a Unix sockit is more efficient than HTTP. So I'd like to have my cake and eat it too. ;-) HTTP may be my fallback plan if I can't figure this out. > > > > Should be more efficient...but really need the extra performance? > > For this point, the uwsgi.ini file should be came a same permission > user:group. I remember having a problem in Centos 7 for this > situation. > > If run for the normal users system you can move the socket another > places, example /var/run/.... with the Nginx user/group names > permission. Or add the users in a group for uwsgi where www-data be > part of this group too > > So, if you can share some information about your environment system > (O.S.), Python Version, some configuration could be help to take a > look > Regards! > -- > Rodrigo Ram?rez Norambuena > http://www.rodrigoramirez.com/