Feature summary (what you would like to be able to do and where):
In order to easily check what your bot's user-agent is, it should be added to version.py, which already lists various things that are defined in user-config.py (which you can do with the user-agent too, although of course it has a default – but it would be nice to be able to see what the default is).
Description
Details
| Subject | Repo | Branch | Lines +/- | |
|---|---|---|---|---|
| IMPR: Show user-agent with version script | pywikibot/core | master | +19 -2 | |
| Add test case for User-Agent | pywikibot/core | master | +6 -3 |
Event Timeline
Unfortunately this is not trival. There are several placed where UA are used or can be modified:
comms Module
eventstreams uses http.user_agent(site) but the header can be overridden
http.request uses http.user_agent(site) but the format string can be overridden with a string passed to headers dict. http.request calls http.fetch to proceed.
http.fetch may have an UA depending on use_fake_user_agent parameter passed with this function or the config.use_fake_user_agent_exception and config.use_fake_user_agent settings, the direct headers dict settings.
version Script
Uses '{pwb}' as format string for gerrit request which is replaced py 'Pywikibot/' + pywikibot.__version__
Other Scripts
reflinks and weblinkchecker may use a fake user agent if config.fake_user_agent_default is set for the given script
Conclusion
All we can show with version.py is the default UA for the default Site().
>>> import pywikibot >>> from pywikibot.comms.http import user_agent as ua >>> site = pywikibot.Site() >>> ua() 'Pywikibot/10.6.0.dev0 (g19939) requests/2.32.3 Python/3.13.0.final.0' >>> ua(site) '(wikipedia:de; User:<username>) Pywikibot/10.6.0.dev0 (g19939) requests/2.32.3 Python/3.13.0.final.0'
Thanks for checking, @Xqt!
For most scripts, the user agent will be the default, but with the script name and site info prepended, right? So maybe add that to version.py with a disclaimer saying that it may be overriden by some scripts. Would that work?
Change #1194032 had a related patch set uploaded (by Xqt; author: Xqt):
[pywikibot/core@master] IMPR: Show user-agent with version script
Change #1194684 had a related patch set uploaded (by D3r1ck01; author: Derick Alangi):
[pywikibot/core@master] Add test case for User-Agent
Change #1194684 abandoned by D3r1ck01:
[pywikibot/core@master] Add test case for User-Agent
Change #1194032 merged by jenkins-bot:
[pywikibot/core@master] IMPR: Show user-agent with version script