Manual:Pywikibot/User-agent

From mediawiki.org

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 = ('{script_product} ({script_comments}) {pwb} ({revision}) '
                     '{http_backend} {python}')

For example the result will be:

login (wikipedia:de; User:Xqbot) Pywikibot/3.1.dev0 (g11348) requests/2.21.0 Python/3.7.0.final.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
code The site code No fa, en, wikidata
family Family name of the wiki No wikipedia, wikisource, wikidata
http_backend requests with version Yes requests/2.21.0
lang The code of the wiki No fa, en, test, wikidata Currently it gives the site code instead of the language
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 or SVN 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 ";"
script_product The script that has been running Yes login, nowcommons currently the same as script
username Username that this code is running No Dexbot, Legobot, etc. URL encoded
version pywikibot version No g11348 or s11895 same as revision

The Used column indicates whether that value is used by the default user_agent_format string.


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.

References[edit]