Skip to content

Conversation

@hugovk
Copy link
Contributor

@hugovk hugovk commented Nov 26, 2024

Fixes #1816.

Add a User-Agent header such as:

Hatch/1.12.1.dev42 CPython/3.12.7 HTTPX/0.27.2

Copy link
Member

@cjames23 cjames23 left a comment

Choose a reason for hiding this comment

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

Thanks for providing this! Can you adjust tests to confirm headers as a test to avoid regressions in the future?

@hugovk
Copy link
Contributor Author

hugovk commented Nov 25, 2025

Yes, added, how's this?

Copy link
Contributor

@ofek ofek left a comment

Choose a reason for hiding this comment

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

Thanks!


user_agent = (
f"Hatch/{__version__} "
f"{platform.python_implementation()}/{platform.python_version()} "
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, can we achieve the same with sys or somehow not use platform? This is purely theoretical as it wouldn't matter when we're doing something heavy already like making network requests.

❯ python -m timeit -n 1 -r 1 "import platform"
1 loop, best of 1: 5.52 msec per loop

Copy link
Member

Choose a reason for hiding this comment

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

It can be done with sys.implementation.name and sys.implementation.version

@cjames23 cjames23 merged commit 9d25ed0 into pypa:master Nov 26, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Send a unique User-Agent header

3 participants