Skip to content
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

bugfix: user-agent python-requests #8394

Merged
merged 8 commits into from
Sep 11, 2023
5 changes: 4 additions & 1 deletion src/poetry/utils/authenticator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@

from cachecontrol import CacheControlAdapter
from cachecontrol.caches import FileCache
from requests_toolbelt import user_agent

from poetry.__version__ import __version__
from poetry.config.config import Config
from poetry.exceptions import PoetryException
from poetry.utils.constants import REQUESTS_TIMEOUT
Expand Down Expand Up @@ -193,7 +195,8 @@ def authenticated_url(self, url: str) -> str:
def request(
self, method: str, url: str, raise_for_status: bool = True, **kwargs: Any
) -> requests.Response:
headers = kwargs.get("headers")
headers = kwargs.get("headers", {}) or {}
Copy link
Contributor

@dimbleby dimbleby Sep 5, 2023

Choose a reason for hiding this comment

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

or {} isn't doing anything useful

cf

session.headers["User-Agent"] = self.user_agent
, which does this on the session - it would be consistent here to do the work in create_session().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think or {} covers the potential of there being a headers key in the dict with a None value.

I will apply the UA to the session itself. Thank you for the suggestion.

headers["User-agent"] = user_agent("poetry", __version__)
request = requests.Request(method, url, headers=headers)
credential = self.get_credentials_for_url(url)

Expand Down