Skip to content

You are no longer logged in, so the action could not be completed. #902

@fdeuze

Description

@fdeuze

Setup:

Wikibase Suite 4.1.1 (Wikibase 1.43.3)
Pyhton 3.12
WikibaseIntegrator 0.12.13

Cedentials:

Retrieve bot password from: https://<wikibase_url>/wiki/Special:BotPasswords

Sample code:

import os
import random
from datetime import datetime

from wikibaseintegrator import WikibaseIntegrator, wbi_login
from wikibaseintegrator.wbi_config import config as wbi_config

# Connection to Wikibase
wbi_config["MEDIAWIKI_API_URL"] = os.getenv("MEDIAWIKI_API_URL")
wbi_config["WIKIBASE_URL"] = os.getenv("WIKIBASE_URL")
wbi_config["USER_AGENT"] = os.getenv("USER_AGENT")
wbi_core = WikibaseIntegrator(login=wbi_login.Login(user=os.getenv("USER_NAME"), password=os.getenv("USER_PASSWORD")), is_bot=True)

min_qid = int(os.getenv("MIN_QID"))
min_qid = int(os.getenv("MAX_QID"))

while(True):
    # Token renew
    wbi_core.login.get_edit_token()

    # Retrieve random item
    item = wbi_core.item.get(f"Q{random.randint(min_qid, max_qid)}")
    if item:
        # Edit item
        item.aliases.set("en", datetime.now().isoformat(), action_if_exists=ActionIfExists.REPLACE_ALL)
        item.write()

Description:

The connection to Wikibase is lost after a variable time which seems to be dependent on the volume of data edited.

   new_item.write()
  File "/usr/local/lib/python3.12/site-packages/wikibaseintegrator/entities/item.py", line 171, in write
    json_data = super()._write(data=self.get_json(), **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/wikibaseintegrator/entities/baseentity.py", line 287, in _write
    json_result: dict = edit_entity(data=data, id=entity_id, type=self.type, summary=summary, clear=clear, is_bot=is_bot, allow_anonymous=allow_anonymous,
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/wikibaseintegrator/wbi_helpers.py", line 339, in edit_entity
    return mediawiki_api_call_helper(data=params, is_bot=is_bot, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/wikibaseintegrator/wbi_helpers.py", line 221, in mediawiki_api_call_helper
    return mediawiki_api_call('POST', mediawiki_api_url=mediawiki_api_url, session=session, data=data, headers=headers, max_retries=max_retries, retry_after=retry_after, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/wikibaseintegrator/wbi_helpers.py", line 135, in mediawiki_api_call
    raise MWApiError(json_data['error'])
wikibaseintegrator.wbi_exceptions.MWApiError: 'You are no longer logged in, so the action could not be completed.'
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/wikibaseintegrator/entities/baseentity.py", line 287, in _write
    json_result: dict = edit_entity(data=data, id=entity_id, type=self.type, summary=summary, clear=clear, is_bot=is_bot, allow_anonymous=allow_anonymous,
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/wikibaseintegrator/wbi_helpers.py", line 339, in edit_entity
    return mediawiki_api_call_helper(data=params, is_bot=is_bot, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/wikibaseintegrator/wbi_helpers.py", line 221, in mediawiki_api_call_helper
    return mediawiki_api_call('POST', mediawiki_api_url=mediawiki_api_url, session=session, data=data, headers=headers, max_retries=max_retries, retry_after=retry_after, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/wikibaseintegrator/wbi_helpers.py", line 135, in mediawiki_api_call
    raise MWApiError(json_data['error'])
wikibaseintegrator.wbi_exceptions.MWApiError: 'You are no longer logged in, so the action could not be completed.'

Comments:

Some tests have been tried without success:

  • Adding the regular call to get_edit_token to renew the token
  • Addition of the regular generate_edit_credentials call to force renewal
  • Reconnection in case of an error with a new wbi_core (new WikibaseIntegrator + Login)
  • Regular reconnection before having the error
  • Modification of the is_bot=True parameter in the WikibaseIntegrator constructor
  • Modification of the token_renew_period parameter in the Login constructor

The modification of the is_bot only change the error message:

wikibaseintegrator.wbi_exceptions.MWApiError: 'You do not have the "bot" right, so the action could not be completed.'

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions