| 1 | from vega_datasets.core import Dataset |
| 2 | from urllib.request import urlopen |
| 3 | from urllib.error import HTTPError, URLError |
| 4 | |
| 5 | |
| 6 | def connection_ok() -> bool: |
| 7 | """Check web connection. |
| 8 | Returns True if web connection is OK, False otherwise. |
| 9 | """ |
| 10 | try: |
| 11 | urlopen(Dataset.base_url, timeout=1) |
| 12 | # if an index page is ever added, this will pass through |
| 13 | return True |
| 14 | except HTTPError: |
| 15 | # There's no index for BASE_URL so Error 404 is expected |
| 16 | return True |
| 17 | except URLError: |
| 18 | # This is raised if there is no internet connection |
| 19 | return False |