Skip to content

Commit b8c2331

Browse files
committed
Use proper user-agent for crates.io API
https://crates.io/policies#crawlers Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent 6e94210 commit b8c2331

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/fetchcode/package_managers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ def get_cargo_versions_from_purl(purl):
119119
"""Fetch versions of Rust cargo packages from the crates.io API."""
120120
purl = PackageURL.from_string(purl)
121121
url = f"https://crates.io/api/v1/crates/{purl.name}"
122-
response = get_response(url=url, content_type="json")
122+
response = get_response(
123+
url=url, content_type="json", headers={"User-Agent": "pm_bot"}
124+
)
123125

124126
for version_info in response.get("versions"):
125127
yield PackageVersion(
@@ -260,7 +262,7 @@ def get_conan_versions_from_purl(purl):
260262

261263

262264
@router.route("pkg:github/.*")
263-
def get_conan_versions_from_purl(purl):
265+
def get_github_versions_from_purl(purl):
264266
"""Fetch versions of ``github`` packages using GitHub REST API."""
265267
purl = PackageURL.from_string(purl)
266268
response = get_response(
@@ -324,7 +326,7 @@ def trim_go_url_path(url_path: str) -> Optional[str]:
324326
and returns the remaining the module name.
325327
For example:
326328
>>> module = "github.com/xx/a"
327-
>>> assert GoproxyVersionAPI.trim_go_url_path("https://github.com/xx/a/b") == module
329+
>>> assert trim_go_url_path("https://github.com/xx/a/b") == module
328330
"""
329331
# some advisories contains this prefix in package name, e.g. https://github.com/advisories/GHSA-7h6j-2268-fhcm
330332
if url_path.startswith("https://pkg.go.dev/"):

0 commit comments

Comments
 (0)