Re: Getting a 401 from requests.get, but not when logging in via the browser.

2020-04-21 Thread dcwhatthe
On Tuesday, April 21, 2020 at 4:38:52 PM UTC-4, Chris Angelico wrote:
> On Wed, Apr 22, 2020 at 6:30 AM Barry Scott barr wrote:
> >
> >
> >
> > > On 21 Apr 2020, at 20:47, dc wrote:
> > >
> > > On Tuesday, April 21, 2020 at 3:16:51 PM UTC-4, Barry Scott wrote:
> > >>> On 21 Apr 2020, at 18:11, dc wrote:
> > >>>
> > >>> On Tuesday, April 21, 2020 at 12:40:25 PM UTC-4, Dieter Maurer wrote:
> >  dc wrote at 2020-4-20 14:48 -0700:
> > > ...
> > > I tried telneting the landing page, i.e. without the specific node 
> > > that requires the login.  So e.g.
> > >
> > > Telnet thissite.oh.gov 80
> > >
> > > , but it returns a 400 Bad Request.  Before that, the Telnet screen 
> > > is completely blank ; I have to press a key before it returns the Bad 
> > > Request.
> > >
> > >
> > > Roger on knowing what the site is asking for.  But I don't know how 
> > > to determine that.
> > 
> >  I use `wget -S` to learn about server responses.
> >  I has the advantage (over `telnet`) to know the HTTP protocl.
> > >>>
> > >>> Sure enough, wget DOES return a lot of information.  In fact, although 
> > >>> an initial response of 401 is returned, it waits for the response and 
> > >>> finally returns a 200.
> > >>>
> > >>> So, I guess the question finally comes down to:  How do we make the 
> > >>> requests.get() wait for a response?  The timeout value isn't the same 
> > >>> thing that I thought it was.  So how do we tell .get() to wait 20 or 30 
> > >>> seconds for an OK response?
> > >>
> > >> The way HTTP protocol works is that you send a request and get a 
> > >> response. 1 in 1 out.
> > >> The response can tell you that you need to do more work, like add 
> > >> authentication data.
> > >>
> > >> The only use of the timeout is to allow you to give up if a response 
> > >> does not comeback
> > >> before you get bored waiting.
> > >>
> > >> In the case of the 401 you can read what it means here: 
> > >> https://httpstatuses.com/401
> > >>
> > >> It is then up to your code to issue a new request with the requirer 
> > >> authentication headers.
> > >> The headers you got back in the first response will tell you what type 
> > >> of authentication is requires,
> > >> basic, digest etc.
> > >>
> > >> The library you are using should be able to handle this if you provide 
> > >> what the library requires from
> > >> you to do the authenticate.
> > >>
> > >> Personally I debug stuff using the curl command. curl -v  shows you 
> > >> the request and the response.
> > >> You can then add curl options to provide authenicate data 
> > >> (username/password) and how to use it --basic
> > >> and --digest for example.
> > >>
> > >> Oh and the other status that needs handling is a 302 redirect. This 
> > >> allows a web site to more a page
> > >> and tell you the new location. Again you have to allow your library to 
> > >> do this for you.
> > >>
> > >> Barry
> > >>
> > >>
> > >>
> > >>>
> > >>> --
> > >>> https://mail.python.org/mailman/listinfo/python-list
> > >>>
> > >
> > > Barry, Thanks.  I'm starting to get a bigger picture, now.
> > >
> > > So I really do need to raise the status, in order to get the headers  I 
> > > had put this in orginally, but then thought it wasn't necessary.
> >
> > In a response you always get a status line, headers and a body. In case of 
> > a response that is not a 200 there is often
> > important information in the headers. The body is usually for showing to 
> > humans when the program does not know
> > how to handle the status code.
> >
> > >
> > > So in the case of this particular site, if I understand correctly, I 
> > > would be using the NTLM to decide which type of Authentication to follow 
> > > up with (I think).
> > >
> > > Content-Length:  1293
> > > Content-Type:text/html
> > > WWW-Authenticate:Negotiate, NTLM
> >
> > Yep that is right. The site wants you to use NTLM to authenticate with it.
> > NTLM is not always supported, you will need to check your library docs to 
> > see if it supports NTLM.
> >
> 
> I believe the 'requests' library supports NTLM, although I haven't
> personally used it so I can't check.
> 
> ChrisA

In this case, I used the requests_ntlm import:

from requests_ntlm import HttpNtlmAuth

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


Re: Getting a 401 from requests.get, but not when logging in via the browser.

2020-04-21 Thread dcwhatthe
On Tuesday, April 21, 2020 at 4:25:54 PM UTC-4, Barry Scott wrote:
> > On 21 Apr 2020, at 20:47, dc wrote:
> > 
> > On Tuesday, April 21, 2020 at 3:16:51 PM UTC-4, Barry Scott wrote:
> >>> On 21 Apr 2020, at 18:11, dc wrote:
> >>> 
> >>> On Tuesday, April 21, 2020 at 12:40:25 PM UTC-4, Dieter Maurer wrote:
>  dc wrote at 2020-4-20 14:48 -0700:
> > ...
> > I tried telneting the landing page, i.e. without the specific node that 
> > requires the login.  So e.g.
> > 
> > Telnet thissite.oh.gov 80
> > 
> > , but it returns a 400 Bad Request.  Before that, the Telnet screen is 
> > completely blank ; I have to press a key before it returns the Bad 
> > Request.
> > 
> > 
> > Roger on knowing what the site is asking for.  But I don't know how to 
> > determine that.
>  
>  I use `wget -S` to learn about server responses.
>  I has the advantage (over `telnet`) to know the HTTP protocl.
> >>> 
> >>> Sure enough, wget DOES return a lot of information.  In fact, although an 
> >>> initial response of 401 is returned, it waits for the response and 
> >>> finally returns a 200.
> >>> 
> >>> So, I guess the question finally comes down to:  How do we make the 
> >>> requests.get() wait for a response?  The timeout value isn't the same 
> >>> thing that I thought it was.  So how do we tell .get() to wait 20 or 30 
> >>> seconds for an OK response?
> >> 
> >> The way HTTP protocol works is that you send a request and get a response. 
> >> 1 in 1 out.
> >> The response can tell you that you need to do more work, like add 
> >> authentication data.
> >> 
> >> The only use of the timeout is to allow you to give up if a response does 
> >> not comeback
> >> before you get bored waiting.
> >> 
> >> In the case of the 401 you can read what it means here: 
> >> https://httpstatuses.com/401
> >> 
> >> It is then up to your code to issue a new request with the requirer 
> >> authentication headers.
> >> The headers you got back in the first response will tell you what type of 
> >> authentication is requires,
> >> basic, digest etc.
> >> 
> >> The library you are using should be able to handle this if you provide 
> >> what the library requires from
> >> you to do the authenticate.
> >> 
> >> Personally I debug stuff using the curl command. curl -v  shows you 
> >> the request and the response.
> >> You can then add curl options to provide authenicate data 
> >> (username/password) and how to use it --basic
> >> and --digest for example.
> >> 
> >> Oh and the other status that needs handling is a 302 redirect. This allows 
> >> a web site to more a page
> >> and tell you the new location. Again you have to allow your library to do 
> >> this for you.
> >> 
> >> Barry
> >> 
> >> 
> >> 
> >>> 
> >>> -- 
> >>> https://mail.python.org/mailman/listinfo/python-list
> >>> 
> > 
> > Barry, Thanks.  I'm starting to get a bigger picture, now.
> > 
> > So I really do need to raise the status, in order to get the headers  I had 
> > put this in orginally, but then thought it wasn't necessary.
> 
> In a response you always get a status line, headers and a body. In case of a 
> response that is not a 200 there is often
> important information in the headers. The body is usually for showing to 
> humans when the program does not know
> how to handle the status code.
> 
> > 
> > So in the case of this particular site, if I understand correctly, I would 
> > be using the NTLM to decide which type of Authentication to follow up with 
> > (I think).
> > 
> > Content-Length:  1293
> > Content-Type:text/html
> > WWW-Authenticate:Negotiate, NTLM
> 
> Yep that is right. The site wants you to use NTLM to authenticate with it.
> NTLM is not always supported, you will need to check your library docs to see 
> if it supports NTLM.
> 
> Barry
> 
> 
> 
> 
> > 
> > -- 
> > https://mail.python.org/mailman/listinfo/python-list 
> > 

I'm pretty much there ; just have to account for other types of Authentication. 
 E.g., for NTLM, I have this:

response.raise_for_status
headers : list = response.headers
type_of_authentication_s : str = headers[ 'WWW-Authenticate' ]
if response_status_code == 401 and 'NTLM' in 
type_of_authentication_s:
response = requests.get(ip_s, auth=HttpNtlmAuth(user_id_s,pw_s 
) )
response_status_code: int = response.status_code


I can take it from here.  Thanks much for your help, sir.


Regards,

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


Re: Getting a 401 from requests.get, but not when logging in via the browser.

2020-04-21 Thread dcwhatthe
On Tuesday, April 21, 2020 at 3:16:51 PM UTC-4, Barry Scott wrote:
> > On 21 Apr 2020, at 18:11, dc wrote:
> > 
> > On Tuesday, April 21, 2020 at 12:40:25 PM UTC-4, Dieter Maurer wrote:
> >> dc wrote at 2020-4-20 14:48 -0700:
> >>> ...
> >>> I tried telneting the landing page, i.e. without the specific node that 
> >>> requires the login.  So e.g.
> >>> 
> >>> Telnet thissite.oh.gov 80
> >>> 
> >>> , but it returns a 400 Bad Request.  Before that, the Telnet screen is 
> >>> completely blank ; I have to press a key before it returns the Bad 
> >>> Request.
> >>> 
> >>> 
> >>> Roger on knowing what the site is asking for.  But I don't know how to 
> >>> determine that.
> >> 
> >> I use `wget -S` to learn about server responses.
> >> I has the advantage (over `telnet`) to know the HTTP protocl.
> > 
> > Sure enough, wget DOES return a lot of information.  In fact, although an 
> > initial response of 401 is returned, it waits for the response and finally 
> > returns a 200.
> > 
> > So, I guess the question finally comes down to:  How do we make the 
> > requests.get() wait for a response?  The timeout value isn't the same thing 
> > that I thought it was.  So how do we tell .get() to wait 20 or 30 seconds 
> > for an OK response?
> 
> The way HTTP protocol works is that you send a request and get a response. 1 
> in 1 out.
> The response can tell you that you need to do more work, like add 
> authentication data.
> 
> The only use of the timeout is to allow you to give up if a response does not 
> comeback
> before you get bored waiting.
> 
> In the case of the 401 you can read what it means here: 
> https://httpstatuses.com/401
> 
> It is then up to your code to issue a new request with the requirer 
> authentication headers.
> The headers you got back in the first response will tell you what type of 
> authentication is requires,
> basic, digest etc.
> 
> The library you are using should be able to handle this if you provide what 
> the library requires from
> you to do the authenticate.
> 
> Personally I debug stuff using the curl command. curl -v  shows you the 
> request and the response.
> You can then add curl options to provide authenicate data (username/password) 
> and how to use it --basic
> and --digest for example.
> 
> Oh and the other status that needs handling is a 302 redirect. This allows a 
> web site to more a page
> and tell you the new location. Again you have to allow your library to do 
> this for you.
> 
> Barry
> 
> 
> 
> > 
> > -- 
> > https://mail.python.org/mailman/listinfo/python-list
> >

Barry, Thanks.  I'm starting to get a bigger picture, now.

So I really do need to raise the status, in order to get the headers  I had put 
this in orginally, but then thought it wasn't necessary.

So in the case of this particular site, if I understand correctly, I would be 
using the NTLM to decide which type of Authentication to follow up with (I 
think).

Content-Length:  1293
Content-Type:text/html
WWW-Authenticate:Negotiate, NTLM

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


Re: Getting a 401 from requests.get, but not when logging in via the browser.

2020-04-21 Thread dcwhatthe
On Tuesday, April 21, 2020 at 12:40:25 PM UTC-4, Dieter Maurer wrote:
> dc wrote at 2020-4-20 14:48 -0700:
> > ...
> >I tried telneting the landing page, i.e. without the specific node that 
> >requires the login.  So e.g.
> >
> >Telnet thissite.oh.gov 80
> >
> >, but it returns a 400 Bad Request.  Before that, the Telnet screen is 
> >completely blank ; I have to press a key before it returns the Bad Request.
> >
> >
> >Roger on knowing what the site is asking for.  But I don't know how to 
> >determine that.
> 
> I use `wget -S` to learn about server responses.
> I has the advantage (over `telnet`) to know the HTTP protocl.

Sure enough, wget DOES return a lot of information.  In fact, although an 
initial response of 401 is returned, it waits for the response and finally 
returns a 200.

So, I guess the question finally comes down to:  How do we make the 
requests.get() wait for a response?  The timeout value isn't the same thing 
that I thought it was.  So how do we tell .get() to wait 20 or 30 seconds for 
an OK response?

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


Re: Getting a 401 from requests.get, but not when logging in via the browser.

2020-04-20 Thread dcwhatthe
On Monday, April 20, 2020 at 5:02:23 PM UTC-4, Eli the Bearded wrote:
> In comp.lang.python,  dc wrote, in reply to me:
> > "What do you think it is doing?"
> > I thought the timeout was waiting for a successful connection.
> 
> A successful *connection* and a successful *authentication* are
> different things. 
> 
> $ telnet example.com 80
> Trying 255.11.22.123...
> Connected to example.com
> Escape character is '^]'.
> 
> [...]
> 
> There's a connection. No authentication, however.
> 
> > "Are you sure the site is using HTTPBasicAuth()? Because if it's not,
> > that would explain how the same credentials can fail. (It could also
> > be something else, like a site returning "401 Unauthorized" because
> > it doesn't like your User-Agent.)"
> > 
> > Yes, that's what I'm getting.
> > 
> > No, I don't know if it's using Basic Authentication.  If I log in
> > through the browser, then it pops up for an id and password.
> > 
> > How do I find out what type of Authentication is applicable?  
> 
> Look at the WWW-Authenticate: header.
> 
> For an example, back to telnet again.
> 
> $ telnet example.com 80
> Trying 255.11.22.123...
> Connected to example.com
> Escape character is '^]'.
> GET /digest/ HTTP/1.1
> Host: example.com
> 
> HTTP/1.1 401 Unauthorized
> Date: Mon, 20 Apr 2020 20:42:25 GMT
> Server: Apache/2.4.41 (Unix) OpenSSL/1.0.2k
> WWW-Authenticate: Digest realm="File Resources", 
> nonce="RyTO776jBQA=5fe3887c65536842f2ebb8ad6cf39bb6b5ec9b66", algorithm=MD5, 
> domain="/digest/", qop="auth"
> Content-Length: 381
> Connection: close
> Content-Type: text/html; charset=iso-8859-1
> ...
> 
> 
> 
> $ telnet example.com 80
> Trying 255.11.22.123...
> Connected to example.com
> Escape character is '^]'.
> GET /basic/ HTTP/1.1
> Host: example.com
> 
> HTTP/1.1 401 Unauthorized
> Date: Mon, 20 Apr 2020 20:45:22 GMT
> Server: Apache/2.4.41 (Unix) OpenSSL/1.0.2k
> WWW-Authenticate: Basic realm="Restricted Resources"
> Content-Length: 381
> Connection: close
> Content-Type: text/html; charset=iso-8859-1
> ...
> 
> 
> There are other ways to authenticate besides those two, but those
> are the ones I've used that operate on the HTTP level and in browsers.
> 
> http://www.iana.org/assignments/http-authschemes/http-authschemes.xhtml
> 
> That list is supposedly all of the auth schemes, I don't know how many
> are widely implemented. Certainly some of them, like "Bearer" I've
> seen for APIs, but not using a browser password GUI. Bearer is a very
> common way to authenticate for APIs.
> 
> If you don't understand what the site is asking for, it may be very
> difficult for you to satisfy it.
> 
> Elijah
> --
> understands all of this at a low level and not well at a library level

Been years since I used Telnet.  I didn't even think that Windows had it 
anymore.

I tried telneting the landing page, i.e. without the specific node that 
requires the login.  So e.g.

Telnet thissite.oh.gov 80

, but it returns a 400 Bad Request.  Before that, the Telnet screen is 
completely blank ; I have to press a key before it returns the Bad Request.


Roger on knowing what the site is asking for.  But I don't know how to 
determine that.

Will continue tomorrow, thanks for your assistance.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting a 401 from requests.get, but not when logging in via the browser.

2020-04-20 Thread dcwhatthe
On Monday, April 20, 2020 at 3:56:46 PM UTC-4, dcwh...@gmail.com wrote:
> On Monday, April 20, 2020 at 3:18:59 PM UTC-4, Eli the Bearded wrote:
> > In comp.lang.python,  dc wrote:
> > > However, one of them immediately returns a 401.  I'm using the exact
> > > same credentials to check this site, as when loggin in.
> > > 
> > > Also, interestingly, it returns the 401 right away.  I tried setting the
> > > timeout value for a ridiculously long time, but it passes the 401 return
> > > immediately.
> > 
> > The timeout presumably is how long to wait for a reply. When the
> > site replies 401 immediately, it's never even bumping up to the
> > timeout.
> > 
> > > Am I misunderstanding the meaning of the timeout parameter?
> > 
> > What do you think it is doing?
> > 
> > > The line in question is 
> > > request = requests.get(ip_s,timeout=5000, verify = False, auth
> > > =HTTPBasicAuth( user_id_s, pw_s))
> > 
> > Are you sure the site is using HTTPBasicAuth()? Because if it's not,
> > that would explain how the same credentials can fail. (It could also
> > be something else, like a site returning "401 Unauthorized" because
> > it doesn't like your User-Agent.)
> > 
> > I use "AuthType Digest" on some of my websites. It's not great, but
> > it's TONS better than basic auth, which sends passwords basically
> > in the clear.
> > 
> > https://en.wikipedia.org/wiki/Digest_access_authentication
> > 
> > In my browser, Digest authentication looks the same GUI-wise as Basic
> > authentication. The differences are all under the hood.
> > 
> > Elijah
> > --
> > digest auth is not as well supported by clients or servers
> 
> 
> "What do you think it is doing?"
> 
> I thought the timeout was waiting for a successful connection.
> 
> 
> "Are you sure the site is using HTTPBasicAuth()? Because if it's not,
> that would explain how the same credentials can fail. (It could also
> be something else, like a site returning "401 Unauthorized" because
> it doesn't like your User-Agent.)"
> 
> Yes, that's what I'm getting.
> 
> No, I don't know if it's using Basic Authentication.  If I log in through the 
> browser, then it pops up for an id and password.
> 
> How do I find out what type of Authentication is applicable?  
> 
> I'll go ahead and try the AuthType that you recommended, for now.
> 
> 
> Thanks and regards,

HTTPDigestAuth() was easy enough to use, same syntax.  But also, same result.  
Just a 401 Unauthorized
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Getting a 401 from requests.get, but not when logging in via the browser.

2020-04-20 Thread dcwhatthe
On Monday, April 20, 2020 at 3:18:59 PM UTC-4, Eli the Bearded wrote:
> In comp.lang.python,  dc wrote:
> > However, one of them immediately returns a 401.  I'm using the exact
> > same credentials to check this site, as when loggin in.
> > 
> > Also, interestingly, it returns the 401 right away.  I tried setting the
> > timeout value for a ridiculously long time, but it passes the 401 return
> > immediately.
> 
> The timeout presumably is how long to wait for a reply. When the
> site replies 401 immediately, it's never even bumping up to the
> timeout.
> 
> > Am I misunderstanding the meaning of the timeout parameter?
> 
> What do you think it is doing?
> 
> > The line in question is 
> > request = requests.get(ip_s,timeout=5000, verify = False, auth
> > =HTTPBasicAuth( user_id_s, pw_s))
> 
> Are you sure the site is using HTTPBasicAuth()? Because if it's not,
> that would explain how the same credentials can fail. (It could also
> be something else, like a site returning "401 Unauthorized" because
> it doesn't like your User-Agent.)
> 
> I use "AuthType Digest" on some of my websites. It's not great, but
> it's TONS better than basic auth, which sends passwords basically
> in the clear.
> 
> https://en.wikipedia.org/wiki/Digest_access_authentication
> 
> In my browser, Digest authentication looks the same GUI-wise as Basic
> authentication. The differences are all under the hood.
> 
> Elijah
> --
> digest auth is not as well supported by clients or servers


"What do you think it is doing?"

I thought the timeout was waiting for a successful connection.


"Are you sure the site is using HTTPBasicAuth()? Because if it's not,
that would explain how the same credentials can fail. (It could also
be something else, like a site returning "401 Unauthorized" because
it doesn't like your User-Agent.)"

Yes, that's what I'm getting.

No, I don't know if it's using Basic Authentication.  If I log in through the 
browser, then it pops up for an id and password.

How do I find out what type of Authentication is applicable?  

I'll go ahead and try the AuthType that you recommended, for now.


Thanks and regards,


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


Getting a 401 from requests.get, but not when logging in via the browser.

2020-04-20 Thread dcwhatthe
I'm validating several sites in a row, and most of them connect successfully.  

However, one of them immediately returns a 401.  I'm using the exact same 
credentials to check this site, as when loggin in.

Also, interestingly, it returns the 401 right away.  I tried setting the 
timeout value for a ridiculously long time, but it passes the 401 return 
immediately.

Am I misunderstanding the meaning of the timeout parameter?


The line in question is 


request = requests.get(ip_s,timeout=5000, verify = False, auth =HTTPBasicAuth( 
user_id_s, pw_s))


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


Re: What variable type is returned from Open()?

2020-04-17 Thread dcwhatthe
On Friday, April 17, 2020 at 2:11:17 PM UTC-4, Rhodri James wrote:
> On 17/04/2020 17:18, dc wrote:
> > Maybe it isn't true for all IDE's or all languages. (I know SOMEONE
> > will interject here, to argue for the sake of arguing). But when I
> > worked with Groovy in Intellij about 5 years ago, there were times
> > when the IDE was confused, during a debugging sessions. I don't
> > remember the exact details, but that anomaly happened only with DEFed
> > variables ; it didn't happen when the data type was specified.
> 
> This is a general problem for IDEs, and type information isn't always 
> helpful.  The number of times I have had to add useless bits of code to 
> cast something to (uint8_t *) because I want to see the bytes and the 
> IDE will not give up on trying to interpret them for me.
> 
> And people wonder why I stick to gdb when at all possible :-)
> 
> -- 
> Rhodri James *-* Kynesim Ltd

Never worked with it.  Is it a debugger for compiled code, i.e. it steps 
through the executable while displaying the source?  Or interpreted code?

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


Re: What variable type is returned from Open()?

2020-04-17 Thread dcwhatthe
Yes,personal preference is definitely a factor and a bias, in these matters.

But aside from trying to make it easier for future A.I. to figure out what the 
heck we humans were doing, it also makes a difference in how the IDE interpets 
the code.

Maybe it isn't true for all IDE's or all languages. (I know SOMEONE will 
interject here, to argue for the sake of arguing). But when I worked with 
Groovy in Intellij about 5 years ago, there were times when the IDE was 
confused, during a debugging sessions. I don't remember the exact details, but 
that anomaly happened only with DEFed variables ; it didn't happen when the 
data type was specified.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-16 Thread dcwhatthe
On Thursday, April 16, 2020 at 2:37:42 PM UTC-4, Chris Angelico wrote:
> On Fri, Apr 17, 2020 at 2:13 AM Richard Damon  wrote:
> > I get the answer: 
> >
> > So that is the name of the type that is returned, at least for that
> > call. One key thing to note is that it begins with a _, so that type is
> > actually an implementation detail, subject to change.
> 
> This is somewhat true; but when the *module* begins with an
> underscore, it often means it's a C accelerator for a Python module.
> You can often find the same thing exposed in a more visible way:
> 
> >>> import io
> >>> io.TextIOWrapper
> 
> 
> And in that location, it is fully documented:
> 
> https://docs.python.org/3/library/io.html#io.TextIOWrapper
> 
> The fact that it comes from the accelerator *is* an internal
> implementation detail, but the class itself is a public one.
> 
> That said, though: it is still very much incorrect to type hint in
> this way. The correct type hint is a generic one:
> 
> https://docs.python.org/3/library/typing.html#typing.IO
> 
> And the correct way to encode this on a variable is to let type
> inference figure it out. You'd use typing.IO or typing.TextIO to
> annotate a function parameter, perhaps, but don't annotate your
> variables at all.
> 
> ChrisA

"And the correct way to encode this on a variable is to let type
inference figure it out. You'd use typing.IO or typing.TextIO to
annotate a function parameter, perhaps, but don't annotate your
variables at all."

I don't know how many times I have to say this, but I've already decided that 
the types of variables are going to be part of my code base.  Same as every 
other language I've programmed in, whether statically or dynamically typed.   

I don't care if it's 'incorrect' for most purposes.  I'm doing it, for my 
specific purpose.

Thanks everyone else, for their assistance on this, and for actually listening 
to the point of the thread.  I'm done with this one.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-16 Thread dcwhatthe
On Thursday, April 16, 2020 at 12:12:23 PM UTC-4, Richard Damon wrote:
> On 4/15/20 9:55 AM, dcw wrote:
> > Hi,
> >
> >
> > As much as possible, I make use of optional type hints.  So if I know a 
> > function returns an integer, then I use
> >
> >
> > this_number_i : int = GetThisNumber()
> >
> >
> > But there's no 'file' type, so I'm not sure what to use as the type for the 
> > return value of an Open() function.
> >
> >
> > config_file : file = open(config_file_s, "r")
> >
> >
> > What type of variable should config_file (above) be declared as?
> >
> Running the simple test program in IDLE:
> 
> 
> f = open("TestFile.txt", "w")
> print (type(f))
> 
> I get the answer: 
> 
> So that is the name of the type that is returned, at least for that
> call. One key thing to note is that it begins with a _, so that type is
> actually an implementation detail, subject to change. This isn't that
> strange in Python as normally you don't really need to know the type of
> an object, but what capabilities the object supports (most from its
> type, but some operations can be just added to the object). This is
> largely because Python is based on a concept call 'Duck-Typing', where
> it is more important if the object quacks like a duck then if it
> technically IS a duck. (And strangely, I believe you can have something
> that technically is a duck, but doesn't quack like one, as well as
> something totally unrelated to the duck type but quacks just like one).
> Files are such an animal, 'fileness' is not based on type, but on
> capability.
> 
> -- 
> Richard Damon

Ok, thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-16 Thread dcwhatthe
On Thursday, April 16, 2020 at 12:09:44 PM UTC-4, Souvik Dutta wrote:
> What are you making?
> 
> Souvik flutter dev
> 
> On Thu, Apr 16, 2020, 9:10 PM  wrote:
> 
> > On Wednesday, April 15, 2020 at 9:46:30 PM UTC-4, Michael Torrie wrote:
> > > On 4/15/20 5:47 PM, dcwh wrote:
> > > > So in the case of Python, whenever the type information is available,
> > > > I want to make it explicit rather than inferred.  Whether the A.I. is
> > > > running a simulation of the software in an IDE, or analyzing them as
> > > > text documents, they should be able to glean as much as possible.
> > > > They should also be able to infer the type, via a Hungarian syntax
> > > > variation.
> > >
> > > Hungarian syntax is definitely an acquired taste, and better suited to
> > > statically-typed languages.
> > >
> > > In this specific case of dealing with open(), keep in mind that most
> > > things that work with files (including something like, for example,
> > > csvreader) only require a file-like object. That can be something that
> > > open() returns, or some other object that implements the semantics. This
> > > is important because anything that can work with files can also work
> > > with any other implementation, provided it speaks the same protocol.
> > > For example you could feed it a stream from a zip archive.  Or a network
> > > stream. Or something else of your own design.  No need for "interface"
> > > classes (although Zope does implement and use them for some reason), or
> > > a special class hierarchy.
> > >
> > > In my opinion, the first line of documentation should be decent
> > > docstrings that document the parameters and return values for functions.
> > > I can think of some cases when type hinting would be desired and
> > > recommended.  But storing the result of open() isn't one of them.
> >
> > Thanks DL Neil, Michael Torrie ; and especially Random832 & Souvik Dutta.
> > Although my coding style is still evolving, I'm already clear on how I
> > personally want to name variables, and the question of clarifying their
> > type.
> >
> > The Docstring of course is the first line of defense, but there's still
> > something missing that I haven't fully worked out yet, regarding the
> > purpose of analyzing the code by an artificial entity.
> >
> > Maybe a json or edn file with the same base filename as the source file,
> > which contains details about the intent of the module.
> >
> > Whatever ; it'll take time to brainstorm something.  Nevertheless, thanks
> > for answering the question that was actually asked, which was the type of
> > variable returned from an Open() statement.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >

The current project is just a utility for checking connectivity, logging, and 
reporting any failures via email.  But the point of the thread applies to any 
project or module.

Regards,

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


Re: What variable type is returned from Open()?

2020-04-16 Thread dcwhatthe
On Wednesday, April 15, 2020 at 9:46:30 PM UTC-4, Michael Torrie wrote:
> On 4/15/20 5:47 PM, dcwh wrote:
> > So in the case of Python, whenever the type information is available,
> > I want to make it explicit rather than inferred.  Whether the A.I. is
> > running a simulation of the software in an IDE, or analyzing them as
> > text documents, they should be able to glean as much as possible.
> > They should also be able to infer the type, via a Hungarian syntax
> > variation.
> 
> Hungarian syntax is definitely an acquired taste, and better suited to
> statically-typed languages.
> 
> In this specific case of dealing with open(), keep in mind that most
> things that work with files (including something like, for example,
> csvreader) only require a file-like object. That can be something that
> open() returns, or some other object that implements the semantics. This
> is important because anything that can work with files can also work
> with any other implementation, provided it speaks the same protocol.
> For example you could feed it a stream from a zip archive.  Or a network
> stream. Or something else of your own design.  No need for "interface"
> classes (although Zope does implement and use them for some reason), or
> a special class hierarchy.
> 
> In my opinion, the first line of documentation should be decent
> docstrings that document the parameters and return values for functions.
> I can think of some cases when type hinting would be desired and
> recommended.  But storing the result of open() isn't one of them.

Thanks DL Neil, Michael Torrie ; and especially Random832 & Souvik Dutta.  
Although my coding style is still evolving, I'm already clear on how I 
personally want to name variables, and the question of clarifying their type.  

The Docstring of course is the first line of defense, but there's still 
something missing that I haven't fully worked out yet, regarding the purpose of 
analyzing the code by an artificial entity.

Maybe a json or edn file with the same base filename as the source file, which 
contains details about the intent of the module.

Whatever ; it'll take time to brainstorm something.  Nevertheless, thanks for 
answering the question that was actually asked, which was the type of variable 
returned from an Open() statement.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-15 Thread dcwhatthe
On Wednesday, April 15, 2020 at 5:28:55 PM UTC-4, Random832 wrote:
> On Wed, Apr 15, 2020, at 12:11, dcwhatthe wrote:
> > So you're saying this is a type _io.TextIOWrapper?  This type doesn't 
> > show up, on the hint listbox (I'm using Wing IDE).  So if I type 
> > var_file : _io, it doesn't show anything.
> 
> While others have pointed out that you shouldn't need a type hint here at all 
> since it can be inferred, the correct type hint to use would be typing.TextIO.

Hi Random832,

I understand the advice, and don't want to get into a debate about it.  But I 
decided years ago, before looking at Python relatively recently, that I want to 
put as much structural & semantic information in my the code as possible.

The primary reason is artificial intelligence.  When intelligent software is 
ready to take over programming, I want to leave it as much information as 
possible.

So in the case of Python, whenever the type information is available, I want to 
make it explicit rather than inferred.  Whether the A.I. is running a 
simulation of the software in an IDE, or analyzing them as text documents, they 
should be able to glean as much as possible.  They should also be able to infer 
the type, via a Hungarian syntax variation.

Yeah, I know it's a minority opinion, and a little kooky.

Thanks for the advice, I'll try typing.TextIO tomorrow.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-15 Thread dcwhatthe
On Wednesday, April 15, 2020 at 1:09:26 PM UTC-4, Souvik Dutta wrote:
> Yes that is the type. You can try using a print(type()) to
> verify that.
> 
> Souvik flutter dev
> 
> On Wed, Apr 15, 2020, 9:45 PM  wrote:
> 
> > On Wednesday, April 15, 2020 at 10:10:31 AM UTC-4, Souvik Dutta wrote:
> > > _io.TextIOWrapper
> > >
> > > On Wed, 15 Apr, 2020, 7:30 pm ,  wrote:
> > >
> > > > Hi,
> > > >
> > > >
> > > > As much as possible, I make use of optional type hints.  So if I know a
> > > > function returns an integer, then I use
> > > >
> > > >
> > > > this_number_i : int = GetThisNumber()
> > > >
> > > >
> > > > But there's no 'file' type, so I'm not sure what to use as the type for
> > > > the return value of an Open() function.
> > > >
> > > >
> > > > config_file : file = open(config_file_s, "r")
> > > >
> > > >
> > > > What type of variable should config_file (above) be declared as?
> > > >
> > > > --
> > > > https://mail.python.org/mailman/listinfo/python-list
> > > >
> >
> > So you're saying this is a type _io.TextIOWrapper?  This type doesn't show
> > up, on the hint listbox (I'm using Wing IDE).  So if I type var_file : _io,
> > it doesn't show anything.
> >
> > Maybe I don't understand what you're saying.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >

Ok, thanks.  It's not showing up in the variable type picklist, so I'll just 
type it in manually, and see what happens, thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: What variable type is returned from Open()?

2020-04-15 Thread dcwhatthe
On Wednesday, April 15, 2020 at 10:10:31 AM UTC-4, Souvik Dutta wrote:
> _io.TextIOWrapper
> 
> On Wed, 15 Apr, 2020, 7:30 pm ,  wrote:
> 
> > Hi,
> >
> >
> > As much as possible, I make use of optional type hints.  So if I know a
> > function returns an integer, then I use
> >
> >
> > this_number_i : int = GetThisNumber()
> >
> >
> > But there's no 'file' type, so I'm not sure what to use as the type for
> > the return value of an Open() function.
> >
> >
> > config_file : file = open(config_file_s, "r")
> >
> >
> > What type of variable should config_file (above) be declared as?
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >

So you're saying this is a type _io.TextIOWrapper?  This type doesn't show up, 
on the hint listbox (I'm using Wing IDE).  So if I type var_file : _io, it 
doesn't show anything.

Maybe I don't understand what you're saying.
-- 
https://mail.python.org/mailman/listinfo/python-list


What variable type is returned from Open()?

2020-04-15 Thread dcwhatthe
Hi,


As much as possible, I make use of optional type hints.  So if I know a 
function returns an integer, then I use


this_number_i : int = GetThisNumber()


But there's no 'file' type, so I'm not sure what to use as the type for the 
return value of an Open() function.


config_file : file = open(config_file_s, "r")


What type of variable should config_file (above) be declared as?

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


Re: how to specify trusted hosts in windows config file

2020-04-05 Thread dcwhatthe
On Sunday, April 5, 2020 at 2:15:21 PM UTC-4, Peter J. Holzer wrote:
> --yrj/dFKFPuw6o+aM
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> Content-Transfer-Encoding: quoted-printable
> 
> On 2020-03-31 08:35:35 +1100, Chris Angelico wrote:
> > On Tue, Mar 31, 2020 at 8:21 AM dc wrote:
> > > For pypi.org alone, my dns lookup differs from yours:  151.101.128.223.
> >=20
> > Ahh, I think I see what's happening. Something's interfering with your
> > DNS - that's a Fastly IP address.
> 
> The four addresses you got were also Fastly addresses:
> 
> | pypi.org. 86278 IN A 151.101.192.223 | pypi.org. 86278 IN A 151.101.64.223 
> | 
> pypi.org. 86278 IN A 151.101.128.223 | pypi.org. 86278 IN A 151.101.0.223
> 
> And in fact the address dcwhatthe gets (151.101.128.223) is one of those four.
> 
> So it doesn't look like something is interfering with DNS.=20
> 
> But maybe something intercepts the SSL connection? Since he wrote that he's 
> at 
> the office, I'm guessing its some kind of malware protection, probably at the 
> corporate firewall.
> 
> A simple way to check this is to open the URL (here https://pypi.org) in the 
> browser and check the certificate. For me it says (in Firefox, other browsers 
> may format the information slightly different):
> 
> Certificate issued to:
> 
>     Python Software Foundation
> Wolfeboro
> New Hampshire, US
> 
> Verified by: DigiCert, Inc.
> 
> dcwhatthe will probably see something different there.
> 
> hp
> 
> --=20
>_  | Peter J. Holzer| Story must make more sense than reality.
> |_|_) ||
> | |   | hjp |-- Charles Stross, "Creative writing
> __/   | http://www.hjp.at/ |   challenge!"
> 
> --yrj/dFKFPuw6o+aM
> Content-Type: application/pgp-signature; name="signature.asc"
> 
> -BEGIN PGP SIGNATURE-
> 
> iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAl6Jry4ACgkQ8g5IURL+
> KF0TnRAAp3r4DxFh24jsXmuLlUykG9Yd4wOloVyGKyajRJjYqQ0AgkTgZrTz6A5N
> 0YVvUnINlY65kkJXA703fb+f7mS7Ij6V3/UvxHGxitLatDauHvlkENTD1GzJzf7l
> Lg05G3krkEpb41S+GLFYO3MVFbeBPV9jUKoHJs96UHxi5tHiTe3IA14xmgooeS32
> 3/JI+wAFV5pR5ICM8sTcRu+9wrNNEtbdg8sNfodIh5d9j3kY7s4SV0srPI3hBRUE
> F949/YAPCA8rH5RcCkM3JQuJeI24hOCBvMXXknjY3pcC4ocAPAXHznTAgNtn8dKd
> Z3uzFkql/7Sd1FK5qIKIvsBUS3TlOvVfbAm8rxZZPitbMEa/GWhDEQq3J5GGrPDx
> 7Sty4TegLa292TJZcEJqDcFEAMjVETGeYRTEkqXdHfbVT8KYy4Lwyka1fLjpFiCC
> mvZdeV2KppO3Kae0ow0mgAOXrLO719ZrgxLrzENA/K4Foq+iOZxozSyGiqjjVzO8
> W7icMQt7sPDCfDfAXxkeEr58yehRdKD6K8gpmQ2inEwk7jAVtauPIUuwlfZzIllm
> 5B6LRAtF7FbZsL1KRzYKtZi2TCPTND/2jW8nUQGaTCEW6W/fa0VLkHhr3sZFmmYA
> I0I3XHyh/At5RCv9XgTtcpchgXvEJlD2D27X08TQNb1k2U7DL6w=
> =crJH
> -END PGP SIGNATURE-
> 
> --yrj/dFKFPuw6o+aM--

Thanks, Peter.  For the time being, I'm dealing with this by doing the 
development on my personal laptop, including the generation of the executable.  
We're all working from home and logging in during the pandemic, anyway.

When this is done and I have the time, I'll try & trace this down, while trying 
to avoid office politics.



Regards,

DC

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


Re: how to specify trusted hosts in windows config file

2020-03-31 Thread dcwhatthe
I don't have control over this, Chris.  This is at my office.  I'm not the 
resource who manages network or other settings.  And we have various 
anti-spyware in place, that at leasts mitigates the risk.

What I'm doing isn't unprecedented.  People get false positives all the time on 
the web, and ask for this type of assistance.  Maybe my results were real 
evidence of something funky, but either way I have to get work done.

Thanks for trying to help, anyway.  I'll do a compare of the refreshed PIP 
files on the office PC, to a copy of pip elsewhere that I know is legit.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to specify trusted hosts in windows config file

2020-03-31 Thread dcwhatthe
On Tuesday, March 31, 2020 at 5:48:50 AM UTC-4, dcwh...@gmail.com wrote:
> On Monday, March 30, 2020 at 5:36:00 PM UTC-4, Chris Angelico wrote:
> > On Tue, Mar 31, 2020 at 8:21 AM  wrote:
> > >
> > > On Monday, March 30, 2020 at 2:49:55 PM UTC-4, Chris Angelico wrote:
> > > > On Tue, Mar 31, 2020 at 5:46 AM dc wrote:
> > > > >
> > > > > These are some of the command lines I've typed, and the results.  It 
> > > > > looks like it's going to https://pypi.org.
> > > > >
> > > > > I have no idea whether that's correct, or not.
> > > > >
> > > > > I'm able to get past the Certificate error with other packages like 
> > > > > requests.  But I just can't update pip.
> > > > >
> > > >
> > > > That is the correct domain name. The question is, does it translate to
> > > > the correct IP address? Try doing a DNS lookup and compare it to the
> > > > results I got.
> > > >
> > > > And, don't think in terms of *getting past the error*. Try to solve
> > > > the actual problem. The certificate error is protecting you against
> > > > installing a forged version of PIP.
> > > >
> > > > ChrisA
> > >
> > > For pypi.org alone, my dns lookup differs from yours:  151.101.128.223.
> > >
> > > Chris,
> > >
> > > Is there a way to just install pip manually, and bypass all this?  I 
> > > mean, if we know we're downloading it from the appropriate ftp or git 
> > > site, then doesn't that in itself avoid a faulty PIP version?
> > >
> > 
> > Ahh, I think I see what's happening. Something's interfering with your
> > DNS - that's a Fastly IP address. I think the best solution would be
> > to undo or bypass whatever's messing with your network, and then
> > you'll be able to use pip normally without any sort of issues.
> > 
> > ChrisA
> 
> Which is what I thought I was trying to do.
> 
> Why does the latest Python come with an earlier version of pip, to begin with?
> 
> Maybe I can update pip on another Win10 PC, identify the changed folders, and 
> copy them over.

Finally got it.  Damn, this was a nightmare:


python get-pip.py --trusted-host pypi.org --trusted-host files.pythonhosted.org

Collecting pip
  Downloading pip-20.0.2-py2.py3-none-any.whl (1.4 MB)
 || 1.4 MB 64 kB/s
Collecting wheel
  Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB)
Installing collected packages: pip, wheel
  Attempting uninstall: pip
Found existing installation: pip 19.2.3
Uninstalling pip-19.2.3:
  Successfully uninstalled pip-19.2.3
Successfully installed pip-20.0.2 wheel-0.34.2

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


Re: how to specify trusted hosts in windows config file

2020-03-31 Thread dcwhatthe
On Monday, March 30, 2020 at 5:36:00 PM UTC-4, Chris Angelico wrote:
> On Tue, Mar 31, 2020 at 8:21 AM  wrote:
> >
> > On Monday, March 30, 2020 at 2:49:55 PM UTC-4, Chris Angelico wrote:
> > > On Tue, Mar 31, 2020 at 5:46 AM dc wrote:
> > > >
> > > > These are some of the command lines I've typed, and the results.  It 
> > > > looks like it's going to https://pypi.org.
> > > >
> > > > I have no idea whether that's correct, or not.
> > > >
> > > > I'm able to get past the Certificate error with other packages like 
> > > > requests.  But I just can't update pip.
> > > >
> > >
> > > That is the correct domain name. The question is, does it translate to
> > > the correct IP address? Try doing a DNS lookup and compare it to the
> > > results I got.
> > >
> > > And, don't think in terms of *getting past the error*. Try to solve
> > > the actual problem. The certificate error is protecting you against
> > > installing a forged version of PIP.
> > >
> > > ChrisA
> >
> > For pypi.org alone, my dns lookup differs from yours:  151.101.128.223.
> >
> > Chris,
> >
> > Is there a way to just install pip manually, and bypass all this?  I mean, 
> > if we know we're downloading it from the appropriate ftp or git site, then 
> > doesn't that in itself avoid a faulty PIP version?
> >
> 
> Ahh, I think I see what's happening. Something's interfering with your
> DNS - that's a Fastly IP address. I think the best solution would be
> to undo or bypass whatever's messing with your network, and then
> you'll be able to use pip normally without any sort of issues.
> 
> ChrisA

Which is what I thought I was trying to do.

Why does the latest Python come with an earlier version of pip, to begin with?

Maybe I can update pip on another Win10 PC, identify the changed folders, and 
copy them over.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: how to specify trusted hosts in windows config file

2020-03-30 Thread dcwhatthe
On Monday, March 30, 2020 at 2:49:55 PM UTC-4, Chris Angelico wrote:
> On Tue, Mar 31, 2020 at 5:46 AM dc wrote:
> >
> > These are some of the command lines I've typed, and the results.  It looks 
> > like it's going to https://pypi.org.
> >
> > I have no idea whether that's correct, or not.
> >
> > I'm able to get past the Certificate error with other packages like 
> > requests.  But I just can't update pip.
> >
> 
> That is the correct domain name. The question is, does it translate to
> the correct IP address? Try doing a DNS lookup and compare it to the
> results I got.
> 
> And, don't think in terms of *getting past the error*. Try to solve
> the actual problem. The certificate error is protecting you against
> installing a forged version of PIP.
> 
> ChrisA

For pypi.org alone, my dns lookup differs from yours:  151.101.128.223.

Chris,

Is there a way to just install pip manually, and bypass all this?  I mean, if 
we know we're downloading it from the appropriate ftp or git site, then doesn't 
that in itself avoid a faulty PIP version?

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


Re: how to specify trusted hosts in windows config file

2020-03-30 Thread dcwhatthe
These are some of the command lines I've typed, and the results.  It looks like 
it's going to https://pypi.org.

I have no idea whether that's correct, or not.

I'm able to get past the Certificate error with other packages like requests.  
But I just can't update pip.

:


[C:\TCMD25]python -m pip install  --trusted-host pypi.org --trusted-host 
--upgrade pip
Requirement already satisfied: pip in 
c:\users\blahblah\appdata\local\programs\python\python38-32\lib\site-packages 
(19.2.3)
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' 
command.


[C:\..\Python\Python38-32\Scripts]python -m pip install --verbose 
--trusted-host pypi.org --trusted-host --upgrade pip
Created temporary directory: ...
Created requirements tracker ...
Requirement already satisfied: pip in 
c:\users\dBlah2\appdata\local\programs\python\python38-32\lib\site-packages 
(19.2.3)
Cleaning up...
Removed build tracker 
'C:\\Users\\DBlah2\\AppData\\Local\\Temp\\pip-req-tracker-1djqfhix'
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' 
command.



[C:\..\Python\Python38-32\Scripts]python -m pip --verbose install --upgrade 
pip
Created temporary directory: ...
Created requirements tracker ...
1 location(s) to search for versions of pip:
* https://pypi.org/simple/pip/
Getting page https://pypi.org/simple/pip/
Found index url https://pypi.org/simple
Looking up "https://pypi.org/simple/pip/; in the cache
Request header has "max_age" as 0, cache bypassed
Starting new HTTPS connection (1): pypi.org:443
Incremented Retry for (url='/simple/pip/'): Retry(total=4, connect=None, 
read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, 
status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, 
'[SSL: CERTIFIC
ATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer 
certificate (_ssl.c:1108)'))': /simple/pip/
Starting new HTTPS connection (2): pypi.org:443
Incremented Retry for (url='/simple/pip/'): Retry(total=3, connect=None, 
read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, 
status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, 
'[SSL: CERTIFIC
ATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer 
certificate (_ssl.c:1108)'))': /simple/pip/
Starting new HTTPS connection (3): pypi.org:443
Incremented Retry for (url='/simple/pip/'): Retry(total=2, connect=None, 
read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, 
status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, 
'[SSL: CERTIFIC
ATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer 
certificate (_ssl.c:1108)'))': /simple/pip/
Starting new HTTPS connection (4): pypi.org:443
Incremented Retry for (url='/simple/pip/'): Retry(total=1, connect=None, 
read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, 
status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, 
'[SSL: CERTIFIC
ATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer 
certificate (_ssl.c:1108)'))': /simple/pip/
Starting new HTTPS connection (5): pypi.org:443
Incremented Retry for (url='/simple/pip/'): Retry(total=0, connect=None, 
read=None, redirect=None, status=None)
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, 
status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, 
'[SSL: CERTIFIC
ATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer 
certificate (_ssl.c:1108)'))': /simple/pip/
Starting new HTTPS connection (6): pypi.org:443
Could not fetch URL https://pypi.org/simple/pip/: There was a problem 
confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): 
Max retries exceed
ed with url: /simple/pip/ (Caused by SSLError(SSLCertVerificationError(1, 
'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get 
local issuer certif
icate (_ssl.c:1108)'))) - skipping
Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
Given no hashes to check 0 links for project 'pip': discarding no candidates
Installed version (19.2.3) is most up-to-date (past versions: none)
Requirement already up-to-date: pip in 
c:\users\dBlah2\appdata\local\programs\python\python38-32\lib\site-packages 
(19.2.3)
Cleaning up...
Removed build tracker 
'C:\\Users\\DBlah2\\AppData\\Local\\Temp\\pip-req-tracker-x0doslyv'
WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' 
command.



-- 

Re: how to specify trusted hosts in windows config file

2020-03-30 Thread dcwhatthe
On Monday, March 30, 2020 at 12:08:54 PM UTC-4, Chris Angelico wrote:
> On Tue, Mar 31, 2020 at 2:31 AM wrote:
> >
> > Hi,
> >
> > I'm able to get past the
> >
> > CERTIFICATE_VERIFY_FAILED
> >
> >
> > error with various packages by specifying trusted host on the command line.
> >
> >
> > But I can't seem to upgrade pip itself.  I keep getting the message
> >
> > "You are using pip version 19.2.3, however 20.0.2 is available."
> >
> > But none of the commands on the web seem to be able to upgrade pip, without 
> > getting either the CERTIFICATE_VERIFY_FAILED error, or the above message.
> >
> 
> Before trying to solve the symptom, see what the underlying problem
> is. Are you actually sure you're getting to the right server? Maybe
> the actual problem is that you aren't able to connect to the true
> PyPI, and that's what the cert failure is warning you of.
> 
> ChrisA

Hi ChrisA,

Nope, I'm not certain.  I just copied and pasted a command line on the web.  
The command line doesn't specify a server.

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


Re: how to specify trusted hosts in windows config file

2020-03-30 Thread dcwhatthe
On Monday, March 30, 2020 at 12:09:48 PM UTC-4, MRAB wrote:
> On 2020-03-30 16:25, dcwhatthe wrote:
> > Hi,
> > 
> > I'm able to get past the
> > 
> > CERTIFICATE_VERIFY_FAILED
> > 
> > 
> > error with various packages by specifying trusted host on the command line.
> > 
> > 
> > But I can't seem to upgrade pip itself.  I keep getting the message
> > 
> > "You are using pip version 19.2.3, however 20.0.2 is available."
> > 
> > But none of the commands on the web seem to be able to upgrade pip, without 
> > getting either the CERTIFICATE_VERIFY_FAILED error, or the above message.
> > 
> > 
> > There are mentions of a pip.ini file that can be edited bypass the 
> > Certificate errors.  But I've done a global search on my hard drive, and 
> > cannot locate this pip.ini.
> > 
> > 
> > Is there some way of simply downloading the latest pip version, and 
> > extracting into the python\scripts folder?
> > 
> Have you tried:
> 
> py -m pip install --upgrade pip

Yes.  CERTIFICATE error.
-- 
https://mail.python.org/mailman/listinfo/python-list


how to specify trusted hosts in windows config file

2020-03-30 Thread dcwhatthe
Hi,

I'm able to get past the 

CERTIFICATE_VERIFY_FAILED


error with various packages by specifying trusted host on the command line.


But I can't seem to upgrade pip itself.  I keep getting the message

"You are using pip version 19.2.3, however 20.0.2 is available."

But none of the commands on the web seem to be able to upgrade pip, without 
getting either the CERTIFICATE_VERIFY_FAILED error, or the above message.


There are mentions of a pip.ini file that can be edited bypass the Certificate 
errors.  But I've done a global search on my hard drive, and cannot locate this 
pip.ini.


Is there some way of simply downloading the latest pip version, and extracting 
into the python\scripts folder?





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


How to cover connection exception errors, and exit

2020-03-28 Thread dcwhatthe
Hi,

I've tried urllib, requests, and some other options.  But I haven't found a way 
to trap certain urls that aren't possible to connect from, outside the office.  
In those cases, I need to just output an error.


So, the following code will cover the 404s and similar errors for most of the 
problem IPs and urls.  But for these particular problem urls, while debugging 
it keeps transferring control to adapters.py, and outputting 

 requests.exceptions.ConnectionError: 
 HTTPSConnectionPool(host='xxx.state.gov', port=443): Max retries 
 exceeded with url: /xxx/xxx/xxx(Caused by 
 NewConnectionError(': Failed to establish a new connection: [Errno 11001] 
 getaddrinfo failed'))


How do I trap this error, without invoking adapters.py?


I've tried many things, but the most recent is this code, from the web:



try:
r = requests.get(url,timeout=3)
r.raise_for_status()
except requests.exceptions.HTTPError as errh:
print ("Http Error:",errh)
except requests.exceptions.ConnectionError as errc:
print ("Error Connecting:",errc)
except requests.exceptions.Timeout as errt:
print ("Timeout Error:",errt)
except requests.exceptions.RequestException as err:
print ("OOps: Something Else",err)


It seems like the error should be trapped by the exception above 
requests.exceptions.ConnectionError, but instead its' hitting adapters.py.


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


Re: How come logging.error writes to a file, but not logging.debug or loggi

2020-03-27 Thread dcwhatthe
On Friday, March 27, 2020 at 3:15:50 PM UTC-4, dcwhatthe wrote:
> Hi,
> 
> 
> When we run
> 
> 
> logging.basicConfig( filename = "TestLogging_" +
> datetime.datetime.now().strftime("%Y%m%d_%H%M%S") + ".log" )
> 
> 
> , and then
> 
> logging.error( "Test01\n" )
> logging.debug("Test02\n")
> logging.info("Test03\n")
> logging.error( "Test04\n" )
> 
> 
> , only the error log lines get sent to the file.
> 
> 
> How do I get info() and debug() to go to the file, as well?

Got it.  Someone named Cameron, assisted with this.  For my purposes, I just 
needed to set the minimum level (INFO) inside the basic config function.  From 
there, the logging will take place for INFO and above, i.e. INFO, DEBUG, and 
ERROR in this case:


logging.basicConfig( filename = "TestLogging_" +
 datetime.datetime.now().strftime("%Y%m%d_%H%M%S") + ".log", level = 
logging.INFO )


Thanks, Cameron.


Regards,

DC

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


How come logging.error writes to a file, but not logging.debug or logging.info?

2020-03-26 Thread dcwhatthe
Hi,


When we run


logging.basicConfig( filename = "TestLogging_" +  
datetime.datetime.now().strftime("%Y%m%d_%H%M%S") + ".log" )


, and then

logging.error( "Test01\n" )
logging.debug("Test02\n")
logging.info("Test03\n")
logging.error( "Test04\n" )


, only the error log lines get sent to the file.  


How do I get info() and debug() to go to the file, as well?



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


Re: How to instlal pyodbc, without pip

2020-02-05 Thread dcwhatthe
On Tuesday, February 4, 2020 at 8:53:10 PM UTC-5, Souvik Dutta wrote:
> You might use chocolatey if you like.
> 
> On Tue, 4 Feb, 2020, 11:05 pm , dcwhatthe wrote:
> 
> > Hi,
> >
> > Pip won't work on my desktop, because of the firewalls we have set up.
> >
> > I have the version from github.  Assuming my Python 3.8.1 Home Directory
> > is C:\Python, How can I install pyodbc pyodbc-master.zip?  Which folders
> > should I unzip it into?
> >
> >
> >
> > Regards,
> >
> >
> >
> >
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> >

Thanks DL Neil, Terry, and Souvik,

I was able to install them manually, by going to the ..\libregrtest\ folder, 
copying the .zip there, and running it against the package, thus:

pip install --trusted-host pyodbc-master.zip

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


How to instlal pyodbc, without pip

2020-02-04 Thread dcwhatthe
Hi,

Pip won't work on my desktop, because of the firewalls we have set up.

I have the version from github.  Assuming my Python 3.8.1 Home Directory is 
C:\Python, How can I install pyodbc pyodbc-master.zip?  Which folders should I 
unzip it into?



Regards,




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