Skip to content

fix(pypi): update get_maintainers_of_package to avoid request blocking #1097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/macaron/slsa_analyzer/package_registry/pypi_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,10 @@ def get_package_page(self, package_name: str) -> str | None:
str | None
The package main page.
"""
url = os.path.join(self.registry_url, "project", package_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure why these changes resolve the issue? I tried printing url = os.path.join(self.registry_url, "project", package_name) and it gives the same output as the hardcoded result you've replaced it with. It also seems that response.content.decode("utf-8") and response.text seem to return the same results? Have you been able to avoid the request blocking with this? When I try it I'm still getting blocked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that f"https://pypi.org/project/{package_name}/" works. It seems that the trailing / is essential. Without it, PyPI executes a JavaScript code that sends a POST request and then redirects to the URL with the trailing / appended, and Macaron is not able to follow the POST request.

url = f"https://pypi.org/project/{package_name}/"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AmineRaouane Please add a comment above this line to emphasize why / at the end is important.

response = send_get_http_raw(url)
if response:
html_snippets = response.content.decode("utf-8")
return html_snippets
return response.text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not needed.

return None

def get_maintainers_of_package(self, package_name: str) -> list | None:
Expand Down
Loading