login module#

Library to log the bot in to a wiki account.

class login.BotPassword(suffix, password)[source]#

Bases: object

BotPassword object for storage in password file.

BotPassword function by using a separate password paired with a suffixed username of the form <username>@<suffix>.

Parameters:
  • suffix (str) – Suffix of the login name

  • password (str) – bot password

Raises:

_PasswordFileWarning – suffix improperly specified

login_name(username)[source]#

Construct the login name from the username and suffix.

Parameters:
  • user – username (without suffix)

  • username (str) –

Return type:

str

class login.LoginManager(password=None, site=None, user=None)[source]#

Bases: object

Site login manager.

All parameters default to defaults in user-config.

Parameters:
  • site (Optional[pywikibot.site.BaseSite]) – Site object to log into

  • user (Optional[str]) – username to use. If user is None, the username is loaded from config.usernames.

  • password (Optional[str]) – password to use

Raises:

pywikibot.exceptions.NoUsernameError – No username is configured for the requested site.

botAllowed()[source]#

Check whether the bot is listed on a specific page.

This allows bots to comply with the policy on the respective wiki.

Return type:

bool

check_user_exists()[source]#

Check that the username exists on the site.

See also

API:Users

Raises:

pywikibot.exceptions.NoUsernameError – Username doesn’t exist in user list.

Return type:

None

login(retry=False, autocreate=False)[source]#

Attempt to log into the server.

See also

API:Login

Parameters:
  • retry (bool) – infinitely retry if the API returns an unknown error

  • autocreate (bool) – if true, allow auto-creation of the account using unified login

Raises:

pywikibot.exceptions.NoUsernameError – Username is not recognised by the site.

Return type:

bool

login_to_site()[source]#

Login to the site.

Return type:

None

readPassword()[source]#

Read passwords from a file.

DO NOT FORGET TO REMOVE READ ACCESS FOR OTHER USERS!!! Use chmod 600 password-file.

All lines below should be valid Python tuples in the form (code, family, username, password), (family, username, password) or (username, password) to set a default password for an username. The last matching entry will be used, so default usernames should occur above specific usernames.

For BotPasswords the password should be given as a BotPassword object.

The file must be either encoded in ASCII or UTF-8.

Example:

('my_username', 'my_default_password')
('wikipedia', 'my_wikipedia_user', 'my_wikipedia_pass')
('en', 'wikipedia', 'my_en_wikipedia_user', 'my_en_wikipedia_pass')
('my_username', BotPassword(
 'my_BotPassword_suffix', 'my_BotPassword_password'))
Return type:

None

storecookiedata()[source]#

Store cookie data.

Return type:

None

class login.LoginStatus(value)[source]#

Bases: IntEnum

Enum for Login statuses.

>>> LoginStatus.NOT_ATTEMPTED
LoginStatus(-3)
>>> LoginStatus.IN_PROGRESS.value
-2
>>> LoginStatus.NOT_LOGGED_IN.name
'NOT_LOGGED_IN'
>>> int(LoginStatus.AS_USER)
0
>>> LoginStatus(-3).name
'NOT_ATTEMPTED'
>>> LoginStatus(0).name
'AS_USER'
AS_USER = 0#
IN_PROGRESS = -2#
NOT_ATTEMPTED = -3#
NOT_LOGGED_IN = -1#
class login.OauthLoginManager(password=None, site=None, user=None)[source]#

Bases: LoginManager

Site login manager using OAuth.

All parameters default to defaults in user-config.

Parameters:
  • site (Optional[pywikibot.site.BaseSite]) – Site object to log into

  • user (Optional[str]) – consumer key

  • password (Optional[str]) – consumer secret

Raises:
  • pywikibot.exceptions.NoUsernameError – No username is configured for the requested site.

  • ImportError – mwoauth isn’t installed

property access_token: Optional[Tuple[str, str]]#

Return OAuth access key token and secret token.

See also

API:Tokens

property consumer_token: Tuple[str, str]#

Return OAuth consumer key token and secret token.

See also

API:Tokens

property identity: Optional[Dict[str, Any]]#

Get identifying information about a user via an authorized token.

login(retry=False, force=False)[source]#

Attempt to log into the server.

See also

API:Login

Parameters:
  • retry (bool) – infinitely retry if exception occurs during authentication.

  • force (bool) – force to re-authenticate

Return type:

bool