Best way to check if there is internet?

2QdxY4RzWzUUiLuE at potatochowder.com 2QdxY4RzWzUUiLuE at potatochowder.com
Wed Feb 23 15:04:25 EST 2022


On 2022-02-23 at 09:28:40 -0700,
Akkana Peck <akkana at shallowsky.com> wrote:

> 2QdxY4RzWzUUiLuE at potatochowder.com writes:
> > I think someone said it way upthread:  don't check, just do whatever you
> > came to do, and it will work or it will fail (presumably, your program
> > can tell the difference, regardless of a past snapshot of being able to
> > retrieve data from an arbitrary URL).
> > 
> > EAFP, anyone?
>
> Yes, but the code being discussed is still helpful, if only for
> error handling: yes, the network isn't fully up, but *why" isn't it?
>
> while True:
>     try:
>         do_whatever_I_came_to_do()
>     except NetworkError:
>         net_config_with_good_error_detection()

Sure, after the fact, once things fail, diagnostics are useful.  The
questions that remain are when should you run them, how complex do they
have to be, and how reliable can they be?

> Aside from error handling, it's useful in a network-up script:
> when you've just enabled a network, it's good to check right then if
> there's a captive portal and deal with it. If you just assume that
> the first thing the user wants is to go to an http: page in a
> browser, and so don't bother to check for a captive portal,
> that'll be annoying for people who want to fetch IMAP mail,
> or run ssh, or load an https: page.

Honest questions:  If I'm captured by a portal, do I "have internet"?
If I don't "have internet," who and/or what should detect, report,
and/or fix it?  When?

(As a matter of fact, I'm one of those people who annoyingly has to deal
with captive portals when my only use for the internet is IMAP or SMTP.)


More information about the Python-list mailing list