From ccp at drsb.com.my Fri Jun 5 05:31:36 2020 From: ccp at drsb.com.my (CCP Dragonedge) Date: Fri, 5 Jun 2020 17:31:36 +0800 Subject: [Flask] Displaying Chinese characters Message-ID: Hi, Does anyone have any experience dealing with Chinese characters? In my code, I set a string to Chinese characters: s = [some Chinese characters] At first, Flask choked. So, at the very top of my code, I put: # -*- coding: utf-8 -*- That solved the problem. I could display the string in my templates by just doing {{ s }}. Here's the weird problem. If I write the Chinese characters directly in the template, like so:

{{ s }}

[Chinese characters written directly with my editor]

The browser (Edge) displays the following error: 'utf-8' codec can't decode byte 0xb5 in position 516: invalid start byte I tried putting the following at in the HTML: But that doesn't help. Why can Jinja decode it, but not the browser? Thanks, p -------------- next part -------------- An HTML attachment was scrubbed... URL: From arj.python at gmail.com Fri Jun 5 05:50:44 2020 From: arj.python at gmail.com (Abdur-Rahmaan Janhangeer) Date: Fri, 5 Jun 2020 13:50:44 +0400 Subject: [Flask] Displaying Chinese characters In-Reply-To: References: Message-ID: Greetings, a wild guess but maybe try specifying: simplified chinese ... or traditional chinese ... or chinese ... Also maybe your editor saves the file on a Chinese unsupported encoding? Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius Kind Regards, Abdur-Rahmaan Janhangeer compileralchemy | blog github Mauritius On Fri, Jun 5, 2020 at 1:32 PM CCP Dragonedge wrote: > > Hi, > > Does anyone have any experience dealing with Chinese characters? In my code, I set a string to Chinese characters: > > s = [some Chinese characters] > > At first, Flask choked. So, at the very top of my code, I put: > > # -*- coding: utf-8 -*- > > That solved the problem. I could display the string in my templates by just doing {{ s }}. > > Here's the weird problem. If I write the Chinese characters directly in the template, like so: > > >

{{ s }}

> > >

[Chinese characters written directly with my editor]

> > The browser (Edge) displays the following error: > > 'utf-8' codec can't decode byte 0xb5 in position 516: invalid start byte > > I tried putting the following at in the HTML: > > > > > > But that doesn't help. Why can Jinja decode it, but not the browser? > > Thanks, > p > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask From ccp at drsb.com.my Fri Jun 5 20:58:26 2020 From: ccp at drsb.com.my (CCP Dragonedge) Date: Sat, 6 Jun 2020 08:58:26 +0800 Subject: [Flask] Flask Digest, Vol 60, Issue 1 In-Reply-To: References: Message-ID: Hi, Firstly, thank you for taking the time to think over my problem. I tried your suggestion as per: https://www.w3schools.com/tags/att_lang.asp Unfortunately, no success. > Also maybe your editor saves the file on a Chinese unsupported encoding? I thought about this, too. But if it were my editor, then my putting: {{ session['str_containing_chinese'] }} wouldn't work either, right? But, somehow, it does! Thanks anyway, p ------------------------------ > > Message: 2 > Date: Fri, 5 Jun 2020 13:50:44 +0400 > From: Abdur-Rahmaan Janhangeer > To: CCP Dragonedge > Cc: flask > Subject: Re: [Flask] Displaying Chinese characters > Message-ID: > bqXmuAS88byAxrg at mail.gmail.com> > Content-Type: text/plain; charset="UTF-8" > > Greetings, > > a wild guess but maybe try specifying: > > simplified chinese ... or > traditional chinese ... or > chinese ... > > Also maybe your editor saves the file on a Chinese unsupported encoding? > > Kind Regards, > > Abdur-Rahmaan Janhangeer > compileralchemy | blog > github > Mauritius > > > Kind Regards, > > Abdur-Rahmaan Janhangeer > compileralchemy | blog > github > Mauritius > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From cs at cskk.id.au Sun Jun 7 19:01:47 2020 From: cs at cskk.id.au (Cameron Simpson) Date: Mon, 8 Jun 2020 09:01:47 +1000 Subject: [Flask] Displaying Chinese characters In-Reply-To: References: Message-ID: <20200607230147.GA38953@cskk.homeip.net> On 05Jun2020 17:31, CCP Dragonedge wrote: >Does anyone have any experience dealing with Chinese characters? In my >code, I set a string to Chinese characters: > >s = [some Chinese characters] > >At first, Flask choked. So, at the very top of my code, I put: > ># -*- coding: utf-8 -*- [...] Might I ask what your editor is? Because AFAIK, only editors pay attention to such a string. My suspicion is that your editor has changed the encoding with which it is storing your text. >That solved the problem. I could display the string in my templates by just >doing {{ s }}. > >Here's the weird problem. If I write the Chinese characters directly in the >template, like so: > > >

{{ s }}

> > >

[Chinese characters written directly with my editor]

Again, I suspect your editor, not flask or your browser. >The browser (Edge) displays the following error: > >'utf-8' codec can't decode byte 0xb5 in position 516: invalid start byte This suggests that the data received from the web server are not valid UTF-8. Windows (which I'm inferring you use) is, IIRC, rather fond of UTF-16LE. >I tried putting the following at in the HTML: > > > > > >But that doesn't help. Because the file is not saved as utf-8. This should be testable. Write a tiny one line file _using the editor you're using for flask_: s = [some Chinese characters] Dump it with a hex editor or viewer. Were you on UNIX I'd suggest: od -c your-test-file and: od -x your-test-file Then make a second test file, again, _using the editor you're using for flask_, like this: # -*- coding: utf-8 -*- s = [some Chinese characters] and dump its context with the hex editor/viewer. My expectation is that the former file will use UTF-16LE or similar, and that the latter file will use UTF-8. You may find that your editor has a setting to always use UTF-8. Turn it on. >Why can Jinja decode it, but not the browser? More testing needed, but either because it has made different encoding assumptions or your testing sequence led you to test slightly misordered. It is possible that Jinja loaded the data by correectly inferring the encoding, but _wrote_ a UTF-8 file for delivery to the browser. Cheers, Cameron Simpson From ccp at drsb.com.my Tue Jun 9 23:02:36 2020 From: ccp at drsb.com.my (CCP Dragonedge) Date: Wed, 10 Jun 2020 11:02:36 +0800 Subject: [Flask] Flask Digest, Vol 60, Issue 3 In-Reply-To: References: Message-ID: Dear Cameron, Yes, I made sure to change the encoding to UTF-8 and it now works. My editor (emacs; yes, I know I'm a dinosaur) is very strange. It displayed the characters without any problems, but saved the file as ANSI. Don't know why... Thanks for your help! p Message: 1 > Date: Mon, 8 Jun 2020 09:01:47 +1000 > From: Cameron Simpson > To: CCP Dragonedge > Cc: flask > Subject: Re: [Flask] Displaying Chinese characters > Message-ID: <20200607230147.GA38953 at cskk.homeip.net> > Content-Type: text/plain; charset=us-ascii > > On 05Jun2020 17:31, CCP Dragonedge wrote: > >Does anyone have any experience dealing with Chinese characters? In my > >code, I set a string to Chinese characters: > > > >s = [some Chinese characters] > > > >At first, Flask choked. So, at the very top of my code, I put: > > > ># -*- coding: utf-8 -*- > [...] > > Might I ask what your editor is? Because AFAIK, only editors pay > attention to such a string. > > My suspicion is that your editor has changed the encoding with which it > is storing your text. > > >That solved the problem. I could display the string in my templates by > just > >doing {{ s }}. > > > >Here's the weird problem. If I write the Chinese characters directly in > the > >template, like so: > > > > > >

{{ s }}

> > > > > >

[Chinese characters written directly with my editor]

> > Again, I suspect your editor, not flask or your browser. > > >The browser (Edge) displays the following error: > > > >'utf-8' codec can't decode byte 0xb5 in position 516: invalid start byte > > This suggests that the data received from the web server are not valid > UTF-8. Windows (which I'm inferring you use) is, IIRC, rather fond of > UTF-16LE. > > >I tried putting the following at in the HTML: > > > > > > > > > > > >But that doesn't help. > > Because the file is not saved as utf-8. > > This should be testable. > > Write a tiny one line file _using the editor you're using for flask_: > > s = [some Chinese characters] > > Dump it with a hex editor or viewer. Were you on UNIX I'd suggest: > > od -c your-test-file > > and: > > od -x your-test-file > > Then make a second test file, again, _using the editor you're using for > flask_, like this: > > # -*- coding: utf-8 -*- > s = [some Chinese characters] > > and dump its context with the hex editor/viewer. > > My expectation is that the former file will use UTF-16LE or similar, and > that the latter file will use UTF-8. > > You may find that your editor has a setting to always use UTF-8. Turn it > on. > > >Why can Jinja decode it, but not the browser? > > More testing needed, but either because it has made different encoding > assumptions or your testing sequence led you to test slightly > misordered. > > It is possible that Jinja loaded the data by correectly inferring the > encoding, but _wrote_ a UTF-8 file for delivery to the browser. > > Cheers, > Cameron Simpson > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From ccp at drsb.com.my Tue Jun 9 23:11:51 2020 From: ccp at drsb.com.my (CCP Dragonedge) Date: Wed, 10 Jun 2020 11:11:51 +0800 Subject: [Flask] Microsoft Edge Message-ID: Dear all, Sorry for all the email, but I thought this was important enough to share. My development box is running Windows 10, and as usual, Microsoft decided to update Edge automatically. All of a sudden, my Flask code, which was working fine previously, didn't work anymore. For some reason, Edge kept on calling my error handler (the one registered with the errorhandler() decorator). I modified the function to not do anything. Now my code works again, but I don't think this is ideal, as I'm ignoring the problem rather than fixing it. Anyone have a similar experience? Even when I turn FLASK_DEBUG = 1, I can't see the error handler being raised. It's Microsoft Edge version 83.0.478.45 (64-bit). I haven't tried it out on other browsers yet (will try to find the time to do so). Thanks, p -------------- next part -------------- An HTML attachment was scrubbed... URL: From ccp at drsb.com.my Fri Jun 12 01:17:56 2020 From: ccp at drsb.com.my (CCP Dragonedge) Date: Fri, 12 Jun 2020 13:17:56 +0800 Subject: [Flask] Problem solved! (re Microsoft Edge) Message-ID: Dear all, Just to follow up on my post a couple of days ago. I managed to trace the problem I was having with the new version of Microsoft Edge. It seems it was looking for my favicon.ico file. Of course, I didn't have one, so it was giving me a 404 error. This is really weird because I never encountered this problem until this version of Edge! Anyway, the solution is here: https://flask.palletsprojects.com/en/1.1.x/patterns/favicon/ Thanks, p -------------- next part -------------- An HTML attachment was scrubbed... URL: From coreybrett at gmail.com Fri Jun 12 10:53:18 2020 From: coreybrett at gmail.com (Corey Boyle) Date: Fri, 12 Jun 2020 10:53:18 -0400 Subject: [Flask] Problem solved! (re Microsoft Edge) In-Reply-To: References: Message-ID: Funny you mention that. I had a user report an issue with 404 yesterday to me on his iPhone. After some research, I found that Safari on iOS was requesting "/apple-touch-icon.png" which I did not have, and this was triggering issues with my 2FA code. I did have the favicon.ico file inplace. I'll be using https://realfavicongenerator.net/ to address this issue. On Fri, Jun 12, 2020 at 1:18 AM CCP Dragonedge wrote: > > Dear all, > > Just to follow up on my post a couple of days ago. I managed to trace the problem I was having with the new version of Microsoft Edge. It seems it was looking for my favicon.ico file. > > Of course, I didn't have one, so it was giving me a 404 error. This is really weird because I never encountered this problem until this version of Edge! > > Anyway, the solution is here: https://flask.palletsprojects.com/en/1.1.x/patterns/favicon/ > > Thanks, > p > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask From coreybrett at gmail.com Thu Jun 25 16:46:37 2020 From: coreybrett at gmail.com (Corey Boyle) Date: Thu, 25 Jun 2020 16:46:37 -0400 Subject: [Flask] help writing a query Message-ID: I have something like the following... class TimestampMixin(object): created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) modified_at = db.Column(db.DateTime, default=datetime.datetime.utcnow, onupdate=datetime.datetime.utcnow) class Memo(db.Model, TimestampMixin): __tablename__ = "memos" pk = db.Column(db.Integer, primary_key=True) note = db.Column(db.Text) date = db.Column(db.Date) purpose = db.Column(db.Text) product = db.Column(db.Text) location = db.Column(db.Text) private = db.Column(db.Boolean, default=False, nullable=True) in_person = db.Column(db.Boolean, default=False, nullable=True) rr = db.Column(db.Boolean, default=False, nullable=True) customer_pk = db.Column(db.Integer, db.ForeignKey("customers.pk")) author_pk = db.Column(db.Integer, db.ForeignKey("users.pk")) contact_pk = db.Column(db.Integer, db.ForeignKey("contacts.pk")) r_by_pk = db.Column(db.Integer, db.ForeignKey("users.pk")) recipients = db.relationship("MemoRecipient", backref="memo", cascade="save-update, merge, delete",) comments = db.relationship("MemoComment", backref="memo", cascade="save-update, merge, delete",) reminders = db.relationship("MemoReminder", backref="memo", cascade="save-update, merge, delete",) class MemoRecipient(db.Model): __tablename__ = "memorecipients" pk = db.Column(db.Integer, primary_key=True) memo_pk = db.Column(db.Integer, db.ForeignKey("memos.pk")) user_pk = db.Column(db.Integer, db.ForeignKey("users.pk")) Whenever a Memo is created, it has an author and optionally gets tagged with other users using the MemoRecipient table. I am trying to figure out how to write a query that will give me all the Memos that were authored by (Memo.author_pk) or sent to (MemoRecipient.user_pk) a specific user. I also need to order the results by Memo.modified_at and paginate the results. I'm thinking I need some type of JOIN, I'm just not sure which. Any advice? -------------- next part -------------- An HTML attachment was scrubbed... URL: From arun.4020 at gmail.com Sat Jun 27 11:54:30 2020 From: arun.4020 at gmail.com (Arunmozhi) Date: Sat, 27 Jun 2020 21:24:30 +0530 Subject: [Flask] help writing a query In-Reply-To: References: Message-ID: Something like: Memo.query.filter(Memo.author_pk == ).filter(Memo.MemoRecipient.has(MemoReciepient.pk == wrote: > I have something like the following... > > class TimestampMixin(object): > created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) > modified_at = db.Column(db.DateTime, default=datetime.datetime.utcnow, > onupdate=datetime.datetime.utcnow) > > class Memo(db.Model, TimestampMixin): > > __tablename__ = "memos" > pk = db.Column(db.Integer, primary_key=True) > note = db.Column(db.Text) > date = db.Column(db.Date) > purpose = db.Column(db.Text) > product = db.Column(db.Text) > location = db.Column(db.Text) > private = db.Column(db.Boolean, default=False, nullable=True) > in_person = db.Column(db.Boolean, default=False, nullable=True) > rr = db.Column(db.Boolean, default=False, nullable=True) > > customer_pk = db.Column(db.Integer, db.ForeignKey("customers.pk")) > author_pk = db.Column(db.Integer, db.ForeignKey("users.pk")) > contact_pk = db.Column(db.Integer, db.ForeignKey("contacts.pk")) > r_by_pk = db.Column(db.Integer, db.ForeignKey("users.pk")) > > recipients = db.relationship("MemoRecipient", backref="memo", > cascade="save-update, merge, delete",) > comments = db.relationship("MemoComment", backref="memo", > cascade="save-update, merge, delete",) > reminders = db.relationship("MemoReminder", backref="memo", > cascade="save-update, merge, delete",) > > class MemoRecipient(db.Model): > __tablename__ = "memorecipients" > pk = db.Column(db.Integer, primary_key=True) > > memo_pk = db.Column(db.Integer, db.ForeignKey("memos.pk")) > user_pk = db.Column(db.Integer, db.ForeignKey("users.pk")) > > Whenever a Memo is created, it has an author and optionally gets tagged > with other users using the MemoRecipient table. > > I am trying to figure out how to write a query that will give me all the > Memos that were authored by (Memo.author_pk) or sent to > (MemoRecipient.user_pk) a specific user. I also need to order the results > by Memo.modified_at and paginate the results. I'm thinking I need some type > of JOIN, I'm just not sure which. > > Any advice? > > _______________________________________________ > Flask mailing list > Flask at python.org > https://mail.python.org/mailman/listinfo/flask > -------------- next part -------------- An HTML attachment was scrubbed... URL: From pengyu.ut at gmail.com Tue Jun 30 11:03:36 2020 From: pengyu.ut at gmail.com (Peng Yu) Date: Tue, 30 Jun 2020 10:03:36 -0500 Subject: [Flask] A minimal example to take upload of a file, call a command on the file, then return the output Message-ID: I need a minimal flask example, showing how to take upload of a file, call a command on the file, then return the output. The suppose the command is called mycmd.sh. It is called in the following way. mycmd.sh < input.txt > output.txt The following example is not sufficient for this purpose. Could anybody provide a minimal working example for the scenario that I mentioned? Thanks. https://flask.palletsprojects.com/en/1.1.x/quickstart/ Thanks. -- Regards, Peng