wikibaseintegrator.wbi_login module
Login class for Wikidata. Takes authentication parameters and stores the session cookies and edit tokens.
- class wikibaseintegrator.wbi_login.Clientlogin(user=None, password=None, mediawiki_api_url=None, token_renew_period=1800, user_agent=None, **kwargs)[source]
Bases:
_Login- Parameters:
user (str | None)
password (str | None)
mediawiki_api_url (str | None)
token_renew_period (int)
user_agent (str | None)
kwargs (Any)
- __init__(user=None, password=None, mediawiki_api_url=None, token_renew_period=1800, user_agent=None, **kwargs)[source]
This class is used to log in with a user account
- Parameters:
user (
str|None) – The usernamepassword (
str|None) – The passwordmediawiki_api_url (
str|None) – The URL to the MediaWiki API (default Wikidata)token_renew_period (
int) – Seconds after which a new token should be requested from the Wikidata serveruser_agent (
str|None) – UA string to use for API requests.kwargs (
Any) – Additional parameters to pass to the requests.sessions.Session.post method, such as headers or proxies.
- generate_edit_credentials()
Request an edit token and update the cookie_jar in order to add the session cookie
- Return type:
RequestsCookieJar- Returns:
Returns a json with all relevant cookies, aka cookie jar
- get_edit_cookie()
Can be called in order to retrieve the cookies from an instance of wbi_login.Login
- Return type:
RequestsCookieJar- Returns:
Returns a json with all relevant cookies, aka cookie jar
- get_edit_token()
Can be called in order to retrieve the edit token from an instance of wbi_login.Login
- Return type:
str|None- Returns:
returns the edit token
- get_session()
Returns the requests.Session object used for the login.
- Return type:
Session- Returns:
Object of type requests.Session()
- class wikibaseintegrator.wbi_login.Login(user=None, password=None, mediawiki_api_url=None, token_renew_period=1800, user_agent=None, **kwargs)[source]
Bases:
_Login- Parameters:
user (str | None)
password (str | None)
mediawiki_api_url (str | None)
token_renew_period (int)
user_agent (str | None)
kwargs (Any)
- __init__(user=None, password=None, mediawiki_api_url=None, token_renew_period=1800, user_agent=None, **kwargs)[source]
This class is used to log in with a bot password
- Parameters:
user (
str|None) – The user of the bot password (format <User>@<BotUser>)password (
str|None) – The password generated byt the MediaWikimediawiki_api_url (
str|None) – The URL to the MediaWiki API (default Wikidata)token_renew_period (
int) – Seconds after which a new token should be requested from the Wikidata serveruser_agent (
str|None) – UA string to use for API requests.kwargs (
Any) – Additional parameters to pass to the requests.sessions.Session.post method, such as headers or proxies.
- generate_edit_credentials()
Request an edit token and update the cookie_jar in order to add the session cookie
- Return type:
RequestsCookieJar- Returns:
Returns a json with all relevant cookies, aka cookie jar
- get_edit_cookie()
Can be called in order to retrieve the cookies from an instance of wbi_login.Login
- Return type:
RequestsCookieJar- Returns:
Returns a json with all relevant cookies, aka cookie jar
- get_edit_token()
Can be called in order to retrieve the edit token from an instance of wbi_login.Login
- Return type:
str|None- Returns:
returns the edit token
- get_session()
Returns the requests.Session object used for the login.
- Return type:
Session- Returns:
Object of type requests.Session()
- exception wikibaseintegrator.wbi_login.LoginError[source]
Bases:
ExceptionRaised when there is an issue with the login
- __init__(*args, **kwargs)
- add_note()
Exception.add_note(note) – add a note to the exception
- args
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class wikibaseintegrator.wbi_login.OAuth1(consumer_token=None, consumer_secret=None, access_token=None, access_secret=None, callback_url='oob', mediawiki_api_url=None, mediawiki_index_url=None, token_renew_period=1800, user_agent=None)[source]
Bases:
_Login- Parameters:
consumer_token (str | None)
consumer_secret (str | None)
access_token (str | None)
access_secret (str | None)
callback_url (str)
mediawiki_api_url (str | None)
mediawiki_index_url (str | None)
token_renew_period (int)
user_agent (str | None)
- __init__(consumer_token=None, consumer_secret=None, access_token=None, access_secret=None, callback_url='oob', mediawiki_api_url=None, mediawiki_index_url=None, token_renew_period=1800, user_agent=None)[source]
This class is used to interact with the OAuth1 API.
- Parameters:
consumer_token (
str|None) – The consumer tokenconsumer_secret (
str|None) – The consumer secretaccess_token (
str|None) – The access token (optional )access_secret (
str|None) – The access secret (optional)callback_url (
str) – The callback URL used to finalize the handshakemediawiki_api_url (
str|None) – The URL to the MediaWiki API (default Wikidata)mediawiki_index_url (
str|None) – The URL to the MediaWiki index (default Wikidata)token_renew_period (
int) – Seconds after which a new token should be requested from the Wikidata serveruser_agent (
str|None) – UA string to use for API requests.
- continue_oauth(oauth_callback_data=None)[source]
Continuation of OAuth procedure. Method must be explicitly called in order to complete OAuth. This allows external entities, e.g. websites, to provide tokens through callback URLs directly.
- Parameters:
oauth_callback_data (
str|None) – The callback URL received to a Web app- Return type:
None- Returns:
- edit_token: str | None
- generate_edit_credentials()
Request an edit token and update the cookie_jar in order to add the session cookie
- Return type:
RequestsCookieJar- Returns:
Returns a json with all relevant cookies, aka cookie jar
- get_edit_cookie()
Can be called in order to retrieve the cookies from an instance of wbi_login.Login
- Return type:
RequestsCookieJar- Returns:
Returns a json with all relevant cookies, aka cookie jar
- get_edit_token()
Can be called in order to retrieve the edit token from an instance of wbi_login.Login
- Return type:
str|None- Returns:
returns the edit token
- get_session()
Returns the requests.Session object used for the login.
- Return type:
Session- Returns:
Object of type requests.Session()
- instantiation_time: float
- mediawiki_api_url: str
- session: Session
- token_renew_period: int
- class wikibaseintegrator.wbi_login.OAuth2(consumer_token=None, consumer_secret=None, mediawiki_api_url=None, mediawiki_rest_url=None, token_renew_period=1800, user_agent=None)[source]
Bases:
_Login- Parameters:
consumer_token (str | None)
consumer_secret (str | None)
mediawiki_api_url (str | None)
mediawiki_rest_url (str | None)
token_renew_period (int)
user_agent (str | None)
- __init__(consumer_token=None, consumer_secret=None, mediawiki_api_url=None, mediawiki_rest_url=None, token_renew_period=1800, user_agent=None)[source]
This class is used to interact with the OAuth2 API.
- Parameters:
consumer_token (
str|None) – The consumer tokenconsumer_secret (
str|None) – The consumer secretmediawiki_api_url (
str|None) – The URL to the MediaWiki API (default Wikidata)mediawiki_rest_url (
str|None) – The URL to the MediaWiki REST API (default Wikidata)token_renew_period (
int) – Seconds after which a new token should be requested from the Wikidata serveruser_agent (
str|None) – UA string to use for API requests.
- edit_token: str | None
- generate_edit_credentials()
Request an edit token and update the cookie_jar in order to add the session cookie
- Return type:
RequestsCookieJar- Returns:
Returns a json with all relevant cookies, aka cookie jar
- get_edit_cookie()
Can be called in order to retrieve the cookies from an instance of wbi_login.Login
- Return type:
RequestsCookieJar- Returns:
Returns a json with all relevant cookies, aka cookie jar
- get_edit_token()
Can be called in order to retrieve the edit token from an instance of wbi_login.Login
- Return type:
str|None- Returns:
returns the edit token
- get_session()
Returns the requests.Session object used for the login.
- Return type:
Session- Returns:
Object of type requests.Session()
- instantiation_time: float
- mediawiki_api_url: str
- session: Session
- token_renew_period: int