Skip to content

Commit

Permalink
Set recommended GitHub API headers
Browse files Browse the repository at this point in the history
  • Loading branch information
jwodder committed Nov 9, 2023
1 parent 7e0d09a commit afba1bb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/tinuous/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ def get(self, path: str, **kwargs: Any) -> requests.Response:
r.raise_for_status()
return r

def download(self, path: str, filepath: Path) -> None:
def download(
self, path: str, filepath: Path, headers: dict[str, str] | None = None
) -> None:
i = 0
while True:
try:
try:
r = self.get(path, stream=True)
r = self.get(path, stream=True, headers=headers)
with filepath.open("wb") as fp:
for chunk in r.iter_content(chunk_size=8192):
fp.write(chunk)
Expand Down Expand Up @@ -187,7 +189,7 @@ def download_zipfile(self, path: str, target_dir: Path) -> None:
zippath = Path(fpath)
i = 0
while True:
self.download(path, zippath)
self.download(path, zippath, headers={"Accept": "application/zip"})
try:
with ZipFile(zippath) as zf:
zf.extractall(target_dir)
Expand Down
8 changes: 6 additions & 2 deletions src/tinuous/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ def get_auth_tokens() -> dict[str, str]:
def client(self) -> APIClient:
return APIClient(
"https://api.github.com",
{"Authorization": f"token {self.token}"},
{
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {self.token}",
"X-GitHub-Api-Version": "2022-11-28",
},
is_github=True,
)

Expand Down Expand Up @@ -443,7 +447,7 @@ def download(self, path: Path) -> list[Path]:
self.tag_name,
target,
)
self.client.download(self.download_url, target)
self.client.download(self.download_url, target, headers={"Accept": "*/*"})
return [target]


Expand Down

0 comments on commit afba1bb

Please sign in to comment.