Re: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-08 Thread Albert-Jan Roskam
   I always use NGINX for this. Run Flask/Gunicorn on localhost:5000 and have
   NGINX rewrite https requests to localhost requests. In nginx.conf I
   automatically redirect every http request to https. Static files are
   served by NGINX, not by Gunicorn, which is faster. NGINX also allows you
   to easily set the transfer encoding to gzip
   Albert-Jan
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-08 Thread Skip Montanaro
Thanks all. I was hoping to get away without something more
sophisticated like NGINX. This is just a piddly little archive of an
old mailing list running on a single-core Ubuntu VM somewhere on the
East Coast. Speed is not a real requirement. Load balancing seemed
like overkill to me. Still, I guess if it has to be, then it has to
be.

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Gunicorn - HTTP and HTTPS in the same instance?

2022-01-08 Thread Kirill Ratkin

Hi.
You probably can solve issue on Gunicorn side. But afaik better solution is to 
use http proxy before Gunicorn. This proxy accepts https connection and proxy 
requests to Gunicorn instances as plain http.

This approach gives you:
a) Monitoring on network layer (tcpdump/wireshark shows you req/res on Gunicorn 
instance)
b) Scalability (proxy can spread traffic on several Gunicorn instances)
c) Maintenance (you can gracefully shutdown/restart Gunicorn instances one by 
one) 
d) Security (For example SSL certificate is configured in proxy only. There are 
another useful features which such proxy can do: simple authentication, 
ddos/fail2ban and so on)

Quite often NGINX is better choice for such proxy. But apache is good as well.

Best regards.
Kirill

От: Skip Montanaro
Отправлено: 7 января 2022 г. в 21:54
Кому: Python
Тема: Gunicorn - HTTP and HTTPS in the same instance?

Hopefully some Pythonistas are also Gunicornistas. I've had little success
finding help with a small dilemma in the docs or in other more specific
sources.

I'm testing out a new, small website. It is just Gunicorn+Flask. I'd like
to both listen for HTTP and HTTPS connections. Accordingly, in my config, I
have the Gunicorn process bind to both ports 80 and 443 if running as root:

if IAM_ROOT:
bind = [
'0.0.0.0:443',
'0.0.0.0:80',
]
else:
bind = [
'0.0.0.0:8080',
]

Gunicorn listens on both ports, but insists on SSL/TLS chit chat over port
80, not just port 443 (which seems to work okay). Is there some magic
incantation to get it to just talk HTTP on port 80, or will I need to spin
up two instances? (The non-root config works fine - plain old HTTP over
port 8080.)

Thx,

Skip
-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extracting dataframe column with multiple conditions on row values

2022-01-08 Thread Edmondo Giovannozzi
Il giorno sabato 8 gennaio 2022 alle 02:21:40 UTC+1 dn ha scritto:
> Salaam Mahmood,
> On 08/01/2022 12.07, Mahmood Naderan via Python-list wrote: 
> > I have a csv file like this 
> > V0,V1,V2,V3 
> > 4,1,1,1 
> > 6,4,5,2 
> > 2,3,6,7 
> > 
> > And I want to search two rows for a match and find the column. For 
> > example, I want to search row[0] for 1 and row[1] for 5. The corresponding 
> > column is V2 (which is the third column). Then I want to return the value 
> > at row[2] and the found column. The result should be 6 then.
> Not quite: isn't the "found column" also required?
> > I can manually extract the specified rows (with index 0 and 1 which are 
> > fixed) and manually iterate over them like arrays to find a match. Then I
> Perhaps this idea has been influenced by a similar solution in another 
> programming language. May I suggest that the better-answer you seek lies 
> in using Python idioms (as well as Python's tools)...
> > key1 = 1 
> > key2 = 5
> Fine, so far - excepting that this 'problem' is likely to be a small 
> part of some larger system. Accordingly, consider writing it as a 
> function. In which case, these two "keys" will become 
> function-parameters (and the two 'results' become return-values).
> > row1 = df.iloc[0] # row=[4,1,1,1] 
> > row2 = df.iloc[1] # row=[6,4,5,2]
> This is likely not native-Python. Let's create lists for 'everything', 
> just-because: 
> 
> >>> headings = [ "V0","V1","V2","V3" ] 
> >>> row1 = [4,1,1,1] 
> >>> row2 = [6,4,5,2] 
> >>> results = [ 2,3,6,7 ] 
> 
> 
> Note how I'm using the Python REPL (in a "terminal", type "python" (as 
> appropriate to your OpSys) at the command-line). IMHO the REPL is a 
> grossly under-rated tool, and is a very good means towards 
> trial-and-error, and learning by example. Highly recommended! 
> 
> 
> > for i in range(len(row1)): 
> 
> This construction is very much a "code smell" for thinking that it is 
> not "pythonic". (and perhaps the motivation for this post) 
> 
> In Python (compared with many other languages) the "for" loop should 
> actually be pronounced "for-each". In other words when we pair the 
> code-construct with a list (for example): 
> 
> for each item in the list the computer should perform some suite of 
> commands. 
> 
> (the "suite" is everything 'inside' the for-each-loop - NB my 
> 'Python-betters' will quickly point-out that this feature is not limited 
> to Python-lists, but will work with any :iterable" - ref: 
> https://docs.python.org/3/tutorial/controlflow.html#for-statements) 
> 
> 
> Thus: 
> 
> > for item in headings: print( item ) 
> ... 
> V0 
> V1 
> V2 
> V3 
> 
> 
> The problem is that when working with matrices/matrixes, a math 
> background equips one with the idea of indices/indexes, eg the 
> ubiquitous subscript-i. Accordingly, when reading 'math' where a formula 
> uses the upper-case Greek "sigma" character, remember that it means "for 
> all" or "for each"! 
> 
> So, if Python doesn't use indexing or "pointers", how do we deal with 
> the problem? 
> 
> Unfortunately, at first glance, the pythonic approach may seem 
> more-complicated or even somewhat convoluted, but once the concepts 
> (and/or the Python idioms) are learned, it is quite manageable (and 
> applicable to many more applications than matrices/matrixes!)...
> > if row1[i] == key1: 
> > for j in range(len(row2)): 
> > if row2[j] == key2: 
> > res = df.iloc[:,j] 
> > print(res) # 6 
> > 
> > Is there any way to use built-in function for a more efficient code?
> This is where your idea bears fruit! 
> 
> There is a Python "built-in function": zip(), which will 'join' lists. 
> NB do not become confused between zip() and zip archive/compressed files! 
> 
> Most of the time reference book and web-page examples show zip() being 
> used to zip-together two lists into a single data-construct (which is an 
> iterable(!)). However, zip() will actually zip-together multiple (more 
> than two) "iterables". As the manual says: 
> 
> «zip() returns an iterator of tuples, where the i-th tuple contains the 
> i-th element from each of the argument iterables.» 
> 
> Ah, so that's where the math-idea of subscript-i went! It has become 
> 'hidden' in Python's workings - or putting that another way: Python 
> looks after the subscripting for us (and given that 'out by one' errors 
> in pointers is a major source of coding-error in other languages, 
> thank-you very much Python!) 
> 
> First re-state the source-data as Python lists, (per above) - except 
> that I recommend the names be better-chosen to be more meaningful (to 
> your application)! 
> 
> 
> Now, (in the REPL) try using zip(): 
> 
> >>> zip( headings, row1, row2, results ) 
>  
> 
> Does that seem a very good illustration? Not really, but re-read the 
> quotation from the manual (above) where it says that zip returns an 
> iterator. If we want to see the values an iterator will produce, then 
> turn it into an iterable data-structure, eg: 
> 
> >>> list( zip( headi

Re: A Newspaper for Python Mailing Lists

2022-01-08 Thread Peter J. Holzer
On 2021-12-26 20:40:03 +0400, Abdur-Rahmaan Janhangeer wrote:
> I have started a newspaper (not newsletter) focused
> on interesting reads on Python mailing lists. Don't tag
> on the fact that holiday seasons are the worst times for
> launch according to marketing folks, I started this to note
> down interesting mails. This might also be a great way to
> bring mailing list gems to a wider readership. So, here's
> the url https://pyherald.com/

Something like [LWN](https://lwn.net/) for Python? Neat.

Two suggestions: 

1. Could you add an RSS or Atom feed?

2. CSS «word-break: break-all» seems like a really weird choice for
   English language text. If you really want to break words across
   lines, use «hyphens: auto».

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extracting dataframe column with multiple conditions on row values

2022-01-08 Thread Avi Gross via Python-list

I have to wonder if when something looks like HOMEWORK, if it should be 
answered in detail, let alone using methods beyond what is expected in class.
The goal of this particular project seems to be to find one (or perhaps more) 
columns in some data structure like a dataframe that match two conditions 
(containing a copy of two numbers in one or more places) and then KNOW what 
column it was in. The reason I say that is because the next fairly nonsensical 
request is to then explicitly return what that column has in the row called 2, 
meaning the third row.
Perhaps stated another way: "what it the item in row/address 2 of the column 
that somewhere contains two additional specified contents called key1 and key2" 
My guess is that if the instructor wanted this to be solved using methods being 
taught, then loops may well be a way to go. Python and numpy/pandas make it 
often easier to do things with columns rather than in rows across them, albeit 
many things allow you to specify an axis. So, yes, transposing is a way to go 
that transforms the problem in a way easier to solve without thinking deeply. 
Some other languages allow relatively easy access in both directions of 
horizontally versus vertically. And this may be an example where solving it as 
a list of lists may also be easier. 
Is the solution at the bottom a solution? Before I check, I want to see if I 
understand the required functionality and ask if it is completely and 
unambiguously specified. 
For completeness, the question being asked may need to deal with a uniqueness 
issue. Is it possible multiple columns match the request and thus more than one 
answer is required to be returned? Is the row called 2 allowed to participate 
in the match or must it be excluded and the question becomes to find one (or 
more) columns that contain key1 somewhere else than row 2 and key2 (which may 
have to be different than key1 or not) somewhere else and THEN provide the 
corresponding entry from row 2 and that (or those) column(s)?
So in looking at the solution offered, what exactly was this supposed to do 
when dft is the transpose?
idt = (dft[0] == 1) & (dft[1] == 5)
Was the code (way below in this message) tried out or just written for us to 
ponder? I tried it. I got an answer of:     0 1 2
    V2  1  5  6
That is not my understanding of what was requested. Row 2 (shown transposed as 
a column) is being shown as a whole. The request was for item "2" which would 
be just 6. Something more like this:
print(dft[idt][2])

But the code makes no sense to me.  seems to explicitly test the first column 
(0) to see if it contains a 1 and then the second column (1) to see if it 
contains a 5. Not sure who cares about this hard-wired query as this is not my 
understanding of the question. You want any of the original three rows (now 
transposed)  tested to see if it contains BOTH. 
I may have read the requirements wrong or it may not be explained well. Until I 
am sure what is being asked and whether there is a good reason someone wants a 
different solution, I see no reason to provide yet another solution.But just 
for fund, assuming dft contains the transpose of the original data, will this 
work?
first = dft[dft.values == key1 ]second = first[first.values == key2 
]print(second[2])
I get a 6 as an answer and suppose it could be done in one more complex 
expression if needed! LOL!
-Original Message-
From: Edmondo Giovannozzi 
To: python-list@python.org
Sent: Sat, Jan 8, 2022 8:00 am
Subject: Re: Extracting dataframe column with multiple conditions on row values

Il giorno sabato 8 gennaio 2022 alle 02:21:40 UTC+1 dn ha scritto:
> Salaam Mahmood,
> On 08/01/2022 12.07, Mahmood Naderan via Python-list wrote: 
> > I have a csv file like this 
> > V0,V1,V2,V3 
> > 4,1,1,1 
> > 6,4,5,2 
> > 2,3,6,7 
> > 
> > And I want to search two rows for a match and find the column. For 
> > example, I want to search row[0] for 1 and row[1] for 5. The corresponding 
> > column is V2 (which is the third column). Then I want to return the value 
> > at row[2] and the found column. The result should be 6 then.
> Not quite: isn't the "found column" also required?
> > I can manually extract the specified rows (with index 0 and 1 which are 
> > fixed) and manually iterate over them like arrays to find a match. Then I
> Perhaps this idea has been influenced by a similar solution in another 
> programming language. May I suggest that the better-answer you seek lies 
> in using Python idioms (as well as Python's tools)...
> > key1 = 1 
> > key2 = 5
> Fine, so far - excepting that this 'problem' is likely to be a small 
> part of some larger system. Accordingly, consider writing it as a 
> function. In which case, these two "keys" will become 
> function-parameters (and the two 'results' become return-values).
> > row1 = df.iloc[0] # row=[4,1,1,1] 
> > row2 = df.iloc[1] # row=[6,4,5,2]
> This is likely not native-Python. Let's create lists for 'everything', 
> just-because: 
> 

Re: A Newspaper for Python Mailing Lists

2022-01-08 Thread Abdur-Rahmaan Janhangeer
Well yes XD though LWN covers Py topics well when it wants


1. Yes sure, did not expect RSS interest
2. Excuse my blunder, will do!

On Sun, 9 Jan 2022, 01:15 Peter J. Holzer,  wrote:

> On 2021-12-26 20:40:03 +0400, Abdur-Rahmaan Janhangeer wrote:
> > I have started a newspaper (not newsletter) focused
> > on interesting reads on Python mailing lists. Don't tag
> > on the fact that holiday seasons are the worst times for
> > launch according to marketing folks, I started this to note
> > down interesting mails. This might also be a great way to
> > bring mailing list gems to a wider readership. So, here's
> > the url https://pyherald.com/
>
> Something like [LWN](https://lwn.net/) for Python? Neat.
>
> Two suggestions:
>
> 1. Could you add an RSS or Atom feed?
>
> 2. CSS «word-break: break-all» seems like a really weird choice for
>English language text. If you really want to break words across
>lines, use «hyphens: auto».
>
> hp
>
> --
>_  | Peter J. Holzer| Story must make more sense than reality.
> |_|_) ||
> | |   | h...@hjp.at |-- Charles Stross, "Creative writing
> __/   | http://www.hjp.at/ |   challenge!"
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A Newspaper for Python Mailing Lists

2022-01-08 Thread Paul Bryan
+1 to RSS.

On Sun, 2022-01-09 at 10:28 +0400, Abdur-Rahmaan Janhangeer wrote:
> Well yes XD though LWN covers Py topics well when it wants
> 
> 
> 1. Yes sure, did not expect RSS interest
> 2. Excuse my blunder, will do!
> 
> On Sun, 9 Jan 2022, 01:15 Peter J. Holzer,  wrote:
> 
> > On 2021-12-26 20:40:03 +0400, Abdur-Rahmaan Janhangeer wrote:
> > > I have started a newspaper (not newsletter) focused
> > > on interesting reads on Python mailing lists. Don't tag
> > > on the fact that holiday seasons are the worst times for
> > > launch according to marketing folks, I started this to note
> > > down interesting mails. This might also be a great way to
> > > bring mailing list gems to a wider readership. So, here's
> > > the url https://pyherald.com/
> > 
> > Something like [LWN](https://lwn.net/) for Python? Neat.
> > 
> > Two suggestions:
> > 
> > 1. Could you add an RSS or Atom feed?
> > 
> > 2. CSS «word-break: break-all» seems like a really weird choice for
> >    English language text. If you really want to break words across
> >    lines, use «hyphens: auto».
> > 
> >     hp
> > 
> > --
> >    _  | Peter J. Holzer    | Story must make more sense than
> > reality.
> > > _|_) |    |
> > > >   | h...@hjp.at |    -- Charles Stross, "Creative
> > > > writing
> > __/   | http://www.hjp.at/ |   challenge!"
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> > 

-- 
https://mail.python.org/mailman/listinfo/python-list