Manual:Pywikibot/User-agent
| Pywikibot |
|---|
|
Pywikibot allows you to have customized user-agent. Prior to August 2014[1], pywikibot core users needed to change the format string in http.py. Now the default is defined in config.py as:
user_agent_format = ('{username}/{script} ({script_comments}) {pwb} ({revision}) '
'{python} {http_backend}')
For example the result will be:
Xqbot/login (wikipedia:de; User:Xqbot) Pywikibot/3.1.dev0 (g11348) Python/3.7.0.final.0 requests/2.21.0
This user-agent complies with the Wikimedia User-Agent policy.
As of September 2014[2], change the user-agent by adding a variable 'user_agent_format' to user-config.py, with a string value using any variable in this table:
| Name | Description | Used | Some examples | Remarks |
|---|---|---|---|---|
| http_backend | requests with version | Yes | requests/2.21.0 | |
| pwb | Pywikibot with version | Yes | Pywikibot/3.0.dev0 | |
| python | Python with version | Yes | Python/3.7.0.final.0 | |
| revision | pywikibot version | Yes | g11348 or s11895 | The prefix indicates Git repository |
| script | The script that has been running | No | login, nowcommons | |
| script_comments | site name and user name | Yes | wikipedia:de; User:Xqbot | Additional informations delimited with ";" |
| site | site name | No | wikipedia:fr | Used with script_comments |
| username | Username that this code is running | Yes | Dexbot, Legobot, etc. | URL encoded, used with script_comments |
The Used column indicates whether that value is used by the default user_agent_format string.
Warning: With Pywikibot 11 the variables code, lang and family were removed. They will be replaced by site during deprecation period. The variables script_product and version will be replaced by script and revision during deprecation period.
If you want to make the current user agent better we suggest you to add more direct contacting information like your e-mail address, etc. Pywikibot sends just the script name and version number when you're requesting a third party wiki (like getting the title of an external link in reflinks.py). We do it since we don't want to expose your contact information to third party websites.
As of July 2019[3], if you define user_agent_description config variable, it will be added as a component to script_comments value. This is the recommended way to add contact information to the User-Agent string, e.g. adding to user-config.py a setting like:
user_agent_description = "https://example.org/CoolTool/; CoolTool@example.org"
ATTENTION: Anything you add to user agent needs to be a ISO 8859 character, which means even characters like č, š, or ā are unacceptable.