Skip to content

Commit 0fa563a

Browse files
committed
Make pystac pass User-Agent to work around urllib being blocked
1 parent e973546 commit 0fa563a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

pystac/stac_io.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,14 @@ def read_text_from_href(self, href: str) -> str:
302302
with urllib3.request(
303303
"GET",
304304
href,
305-
headers=self.headers,
305+
headers={"User-Agent": "pystac", **self.headers},
306306
preload_content=False, # type: ignore
307307
) as f:
308308
href_contents = f.read().decode("utf-8")
309309
else:
310-
req = Request(href, headers=self.headers)
310+
req = Request(
311+
href, headers={"User-Agent": "pystac", **self.headers}
312+
)
311313
with urlopen(req) as f:
312314
href_contents = f.read().decode("utf-8")
313315

tests/test_stac_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def test_headers_stac_io(request_mock: unittest.mock.MagicMock) -> None:
130130
pystac.Catalog.from_file("https://example.com/catalog.json", stac_io=stac_io)
131131

132132
headers = request_mock.call_args[1]["headers"]
133-
assert headers == stac_io.headers
133+
assert headers == {"User-Agent": "pystac", **stac_io.headers}
134134

135135

136136
@pytest.mark.vcr()

0 commit comments

Comments
 (0)