mediawiki_api_call#

wikibaseintegrator.wbi_helpers.mediawiki_api_call(method, mediawiki_api_url=None, session=None, login=None, max_retries=20, retry_after=60, **kwargs)[source]#

A function to call the MediaWiki API.

Parameters:
  • method (str) – ‘GET’ or ‘POST’

  • mediawiki_api_url (str | None, default: None)

  • session (Session | None, default: None) – If a session is passed, it will be used. Otherwise, the current thread’s default session is used

  • login (_Login | None, default: None) – If provided and the API reports that the session is no longer authenticated (see SESSION_LOST_ERROR_CODES), it is used to fully re-authenticate before retrying, once per call.

  • max_retries (int, default: 20) – The maximum number of tries of the request. The instance asking to slow down (maxlag, rate limiting, HTTP 429, readonly mode) is waited for up to this number of tries. The failures (connection errors, HTTP 5xx, and read timeouts of the READ_ONLY_ACTIONS) are tried at most config[‘BACKOFF_MAX_TRIES’] times, with a wait doubling from 1 second, like wbi_backoff.

  • retry_after (int, default: 60) – The maximum number of seconds to wait between two tries after a failure or a maxlag, and the wait when the instance doesn’t say how long to wait (rate limiting without Retry-After, readonly mode)

  • kwargs (Any) – Any additional keyword arguments to pass to requests.request

Return type:

dict

Returns:

The data returned by the API as a dictionary