Best way to check if there is internet?
Gisle Vanem
gisle.vanem at gmail.com
Wed Feb 9 03:21:41 EST 2022
Abdur-Rahmaan Janhangeer wrote:
> Thanks everybody for the answers. It was very enlightening. Here's my
> solution:
>
> # using rich console
> def ensure_internet():
> console = Console()
> domains = [
> 'https://google.com',
> 'https://yahoo.com',
> 'https://bing.com',
> 'https://www.ecosia.org',
> 'https://www.wikipedia.org'
> ]
> results = []
> with console.status("Checking internet ...", spinner="dots"):
> for domain in domains:
> try:
> requests.get(domain)
> results.append(1)
> except Exception as e:
> results.append(0)
> if not any(results):
> print('No internet connection')
> sys.exit()
Was this supposed to be a self-contained working
program? It doesn't work here.
Were/what is 'Console()' for example?
--
--gv
More information about the Python-list
mailing list