Skip to content

Commit 864b35a

Browse files
kmuehlbauermathausepre-commit-ci[bot]
authored
add 'User-Agent'-header to pooch.retrieve (#9782)
* add 'User-Agent'-header to pooch.retrieve * try sys.modules * Apply suggestions from code review Co-authored-by: Mathias Hauser <mathause@users.noreply.github.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add whats-new.rst entry --------- Co-authored-by: Mathias Hauser <mathause@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 4c8b03b commit 864b35a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

doc/whats-new.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Bug fixes
6464
By `Pascal Bourgault <https://github.com/aulemahal>`_.
6565
- Fix CF decoding of ``grid_mapping`` to allow all possible formats, add tests (:issue:`9761`, :pull:`9765`).
6666
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
67+
- Add `User-Agent` to request-headers when retrieving tutorial data (:issue:`9774`, :pull:`9782`)
68+
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
6769

6870
Documentation
6971
~~~~~~~~~~~~~

xarray/tutorial.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import os
1212
import pathlib
13+
import sys
1314
from typing import TYPE_CHECKING
1415

1516
import numpy as np
@@ -157,8 +158,13 @@ def open_dataset(
157158

158159
url = f"{base_url}/raw/{version}/{path.name}"
159160

161+
headers = {"User-Agent": f"xarray {sys.modules['xarray'].__version__}"}
162+
downloader = pooch.HTTPDownloader(headers=headers)
163+
160164
# retrieve the file
161-
filepath = pooch.retrieve(url=url, known_hash=None, path=cache_dir)
165+
filepath = pooch.retrieve(
166+
url=url, known_hash=None, path=cache_dir, downloader=downloader
167+
)
162168
ds = _open_dataset(filepath, engine=engine, **kws)
163169
if not cache:
164170
ds = ds.load()

0 commit comments

Comments
 (0)