Page MenuHomePhabricator

AttributeError: 'Family' object has no attribute '_userinfo' when using Pywikibot
Closed, ResolvedPublic

Description

Hi,
when I want to run patrol.py script with Pywikibot, I get this:

kizule@kizule-laptop:~/Desktop/development/pywikibot-core$ python pwb.py patrol -usercontribs:Antioksidans -ask
Processing user: Antioksidans
Newpages:
Loading Корисник:Zoranzoki21/patrol_whitelist
Traceback (most recent call last):
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 902, in __getattr__
    method = getattr(self.family, attr)
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/family.py", line 979, in __getattribute__
    return super(Family, self).__getattribute__(name)
AttributeError: 'Family' object has no attribute '_userinfo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pwb.py", line 325, in <module>
    if not main():
  File "pwb.py", line 320, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 101, in run_python_file
    main_mod.__dict__)
  File "./scripts/patrol.py", line 505, in <module>
    main()
  File "./scripts/patrol.py", line 490, in main
    bot.run(feed)
  File "./scripts/patrol.py", line 286, in run
    for page in feed:
  File "./scripts/patrol.py", line 410, in api_feed_repeater
    for page in generator:
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 6699, in newpages
    total=total
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/tools/__init__.py", line 1757, in wrapper
    return obj(*__args, **__kw)
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 4795, in recentchanges
    self.has_right('patrol') or self.has_right('patrolmarks')):
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/tools/__init__.py", line 1840, in wrapper
    return obj(*new_args, **new_kwargs)
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 2283, in has_right
    return right.lower() in self._userinfo['rights']
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 911, in __getattr__
    % (self.__class__.__name__, attr))
AttributeError: APISite instance has no attribute '_userinfo'
CRITICAL: Exiting due to uncaught exception <class 'AttributeError'>
kizule@kizule-laptop:~/Desktop/development/pywikibot-core$

Version (python pwb.py version):

Pywikibot: [ssh] pywikibot-core (bd078a4, g11864, 2020/01/27, 20:13:08, ok)
Release version: 3.1.dev0
requests version: 2.21.0
  cacerts: /etc/ssl/certs/ca-certificates.crt
    certificate test: ok
Python: 3.7.5 (default, Nov 20 2019, 09:21:52) 
[GCC 9.2.1 20191008]
PYWIKIBOT_DIR: Not set
PYWIKIBOT_DIR_PWB: 
PYWIKIBOT_NO_USER_CONFIG: Not set
Config base dir: /home/kizule/Desktop/development/pywikibot-core
Usernames for family "wikisource":
        sr: Zoranzoki21
Usernames for family "wikinews":
        sr: Zoranzoki21
Usernames for family "wikibooks":
        sr: Zoranzoki21
Usernames for family "wikiquote":
        sr: Zoranzoki21
Usernames for family "wiktionary":
        sr: Zoranzoki21
        hr: Zoranzoki21
Usernames for family "wikipedia":
        sr: Zoranzoki21
Usernames for family "wikidata":
        wikidata: Zoranzoki21

Event Timeline

Kizule triaged this task as High priority.Jan 27 2020, 9:43 PM
Kizule created this task.

I tried now updating requirements, but this still happens:

kizule@kizule-laptop:~/Desktop/development/pywikibot-core$ pip check
launchpadlib 1.10.7 requires testresources, which is not installed.
requests-oauthlib 1.3.0 has requirement oauthlib>=3.0.0, but you have oauthlib 2.1.0.
kizule@kizule-laptop:~/Desktop/development/pywikibot-core$ pip install -r requirements.txt
Ignoring requests: markers 'python_version == "3.4"' don't match your environment
Ignoring enum34: markers 'python_version < "3"' don't match your environment
Ignoring requests: markers 'python_full_version > "2.7.6" and python_full_version < "2.7.9"' don't match your environment
Ignoring ipaddr: markers 'python_version < "3"' don't match your environment
Ignoring unicodecsv: markers 'python_version < "3"' don't match your environment
Ignoring Pillow: markers 'python_version < "3"' don't match your environment
Ignoring Pillow: markers 'python_version == "3.4"' don't match your environment
Requirement already satisfied: requests>=2.20.1 in /usr/lib/python3/dist-packages (from -r requirements.txt (line 23)) (2.21.0)
Requirement already satisfied: mwoauth!=0.3.1,>=0.2.4 in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 33)) (0.3.7)
Requirement already satisfied: pydot>=1.2 in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 36)) (1.4.1)
Collecting python-stdnum>=1.13 (from -r requirements.txt (line 42))
  Downloading https://files.pythonhosted.org/packages/6b/57/5d1ee250a9c4e780d57d7dcc1b9553c4e386c759ed3087f813965c4534d2/python_stdnum-1.13-py2.py3-none-any.whl (839kB)
    100% |████████████████████████████████| 849kB 758kB/s 
Collecting Pillow>=6.2.1 (from -r requirements.txt (line 47))
  Downloading https://files.pythonhosted.org/packages/f5/79/b2d5695d1a931474fa68b68ec93bdf08ba9acbc4d6b3b628eb6aac81d11c/Pillow-7.0.0-cp37-cp37m-manylinux1_x86_64.whl (2.1MB)
    100% |████████████████████████████████| 2.1MB 331kB/s 
Requirement already satisfied: google>=1.7 in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 50)) (2.0.3)
Requirement already satisfied: sseclient!=0.0.23,!=0.0.24,>=0.0.18 in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 51)) (0.0.22)
Requirement already satisfied: flickrapi in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 54)) (2.4.0)
Requirement already satisfied: mwparserfromhell>=0.3.3 in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 57)) (0.5.4)
Requirement already satisfied: PyMySQL in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 60)) (0.9.3)
Requirement already satisfied: beautifulsoup4 in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 63)) (4.8.2)
Requirement already satisfied: pycountry in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 66)) (19.8.18)
Requirement already satisfied: memento_client!=0.6.0,>=0.5.1 in /home/kizule/.local/lib/python3.7/site-packages (from -r requirements.txt (line 69)) (0.6.1)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from mwoauth!=0.3.1,>=0.2.4->-r requirements.txt (line 33)) (1.12.0)
Requirement already satisfied: oauthlib in /usr/lib/python3/dist-packages (from mwoauth!=0.3.1,>=0.2.4->-r requirements.txt (line 33)) (2.1.0)
Requirement already satisfied: PyJWT<2.0.0,>=1.0.1 in /usr/lib/python3/dist-packages (from mwoauth!=0.3.1,>=0.2.4->-r requirements.txt (line 33)) (1.7.0)
Requirement already satisfied: requests-oauthlib in /home/kizule/.local/lib/python3.7/site-packages (from mwoauth!=0.3.1,>=0.2.4->-r requirements.txt (line 33)) (1.3.0)
Requirement already satisfied: pyparsing>=2.1.4 in /home/kizule/.local/lib/python3.7/site-packages (from pydot>=1.2->-r requirements.txt (line 36)) (2.4.6)
Requirement already satisfied: requests-toolbelt>=0.3.1 in /home/kizule/.local/lib/python3.7/site-packages (from flickrapi->-r requirements.txt (line 54)) (0.9.1)
Requirement already satisfied: soupsieve>=1.2 in /home/kizule/.local/lib/python3.7/site-packages (from beautifulsoup4->-r requirements.txt (line 63)) (1.9.5)
Installing collected packages: python-stdnum, Pillow
  Found existing installation: python-stdnum 1.12
    Uninstalling python-stdnum-1.12:
      Successfully uninstalled python-stdnum-1.12
Successfully installed Pillow-7.0.0 python-stdnum-1.13
kizule@kizule-laptop:~/Desktop/development/pywikibot-core$ pip install -r requests-requirements.txt
Processing /home/kizule/Desktop/development/pywikibot-core
Requirement already satisfied: pycparser!=2.14 in /home/kizule/.local/lib/python3.7/site-packages (from pywikibot==3.0.20200127.dev0->-r requests-requirements.txt (line 5)) (2.19)
Requirement already satisfied: requests>=2.20.1 in /usr/lib/python3/dist-packages (from pywikibot==3.0.20200127.dev0->-r requests-requirements.txt (line 5)) (2.21.0)
Building wheels for collected packages: pywikibot
  Running setup.py bdist_wheel for pywikibot ... done
  Stored in directory: /home/kizule/.cache/pip/wheels/28/df/cb/5a529c54edd4f8987defa94cd0f11252f292a426388702961e
Successfully built pywikibot
Installing collected packages: pywikibot
  Found existing installation: pywikibot 3.0.20200117.dev0
    Uninstalling pywikibot-3.0.20200117.dev0:
      Successfully uninstalled pywikibot-3.0.20200117.dev0
Successfully installed pywikibot-3.0.20200127.dev0
kizule@kizule-laptop:~/Desktop/development/pywikibot-core$ python pwb.py patrol -usercontribs:Antioksidans -ask
Processing user: Antioksidans
Newpages:
Loading Корисник:Zoranzoki21/patrol_whitelist
Traceback (most recent call last):
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 902, in __getattr__
    method = getattr(self.family, attr)
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/family.py", line 979, in __getattribute__
    return super(Family, self).__getattribute__(name)
AttributeError: 'Family' object has no attribute '_userinfo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pwb.py", line 325, in <module>
    if not main():
  File "pwb.py", line 320, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 101, in run_python_file
    main_mod.__dict__)
  File "./scripts/patrol.py", line 505, in <module>
    main()
  File "./scripts/patrol.py", line 490, in main
    bot.run(feed)
  File "./scripts/patrol.py", line 286, in run
    for page in feed:
  File "./scripts/patrol.py", line 410, in api_feed_repeater
    for page in generator:
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 6699, in newpages
    total=total
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/tools/__init__.py", line 1757, in wrapper
    return obj(*__args, **__kw)
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 4795, in recentchanges
    self.has_right('patrol') or self.has_right('patrolmarks')):
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/tools/__init__.py", line 1840, in wrapper
    return obj(*new_args, **new_kwargs)
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 2283, in has_right
    return right.lower() in self._userinfo['rights']
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 911, in __getattr__
    % (self.__class__.__name__, attr))
AttributeError: APISite instance has no attribute '_userinfo'
CRITICAL: Exiting due to uncaught exception <class 'AttributeError'>
kizule@kizule-laptop:~/Desktop/development/pywikibot-core$
Xqt lowered the priority of this task from High to Medium.
Xqt added subscribers: Huji, Xqt.

Probably you aren’t logged in? Try login.py first.

Anyway this is not an appropriate behaviour and must be fixed

Xqt removed Xqt as the assignee of this task.Jan 28 2020, 6:46 AM

Probably you aren’t logged in? Try login.py first.

Anyway this is not an appropriate behaviour and must be fixed

I think that something is wrong with patrol.py, as delete and few others works correctly.

I think has_right() should first check that logged_in() returns true and only then return right.lower() in self._userinfo['rights']

I still have this problem, this isn't nice.

kizule@kizule-laptop:~/Desktop/development/pywikibot-core$ python pwb.py patrol -usercontribs:Orion1964 -ask
Processing user: Orion1964
Newpages:
Loading Корисник:Zoranzoki21/patrol_whitelist
Traceback (most recent call last):
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 901, in __getattr__
    method = getattr(self.family, attr)
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/family.py", line 979, in __getattribute__
    return super(Family, self).__getattribute__(name)
AttributeError: 'Family' object has no attribute '_userinfo'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pwb.py", line 325, in <module>
    if not main():
  File "pwb.py", line 320, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 101, in run_python_file
    main_mod.__dict__)
  File "./scripts/patrol.py", line 505, in <module>
    main()
  File "./scripts/patrol.py", line 490, in main
    bot.run(feed)
  File "./scripts/patrol.py", line 286, in run
    for page in feed:
  File "./scripts/patrol.py", line 410, in api_feed_repeater
    for page in generator:
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 6698, in newpages
    total=total
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/tools/__init__.py", line 1757, in wrapper
    return obj(*__args, **__kw)
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 4794, in recentchanges
    self.has_right('patrol') or self.has_right('patrolmarks')):
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/tools/__init__.py", line 1840, in wrapper
    return obj(*new_args, **new_kwargs)
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 2282, in has_right
    return right.lower() in self._userinfo['rights']
  File "/home/kizule/Desktop/development/pywikibot-core/pywikibot/site.py", line 910, in __getattr__
    % (self.__class__.__name__, attr))
AttributeError: APISite instance has no attribute '_userinfo'
CRITICAL: Exiting due to uncaught exception <class 'AttributeError'>

Version:

kizule@kizule-laptop:~/Desktop/development/pywikibot-core$ python pwb.py version
Pywikibot: [ssh] pywikibot-core (083ed93, g11892, 2020/02/02, 15:59:21, ok)
Release version: 3.1.dev0
requests version: 2.21.0
  cacerts: /etc/ssl/certs/ca-certificates.crt
    certificate test: ok
Python: 3.7.5 (default, Nov 20 2019, 09:21:52) 
[GCC 9.2.1 20191008]
PYWIKIBOT_DIR: Not set
PYWIKIBOT_DIR_PWB: 
PYWIKIBOT_NO_USER_CONFIG: Not set
Config base dir: /home/kizule/Desktop/development/pywikibot-core
Usernames for family "wikisource":
        sr: Zoranzoki21
Usernames for family "wikinews":
        sr: Zoranzoki21
Usernames for family "wikibooks":
        sr: Zoranzoki21
Usernames for family "wikiquote":
        sr: Zoranzoki21
Usernames for family "wiktionary":
        sr: Zoranzoki21
        hr: Zoranzoki21
Usernames for family "wikipedia":
        sr: Zoranzoki21
Usernames for family "wikidata":
        wikidata: Zoranzoki21
kizule@kizule-laptop:~/Desktop/development/pywikibot-core$

I experience the same problem as Zoranzoki21 since January 23.

Change 571001 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] always use Site.userinfo in favour of Site._userinfo

https://gerrit.wikimedia.org/r/571001

Change 571001 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] always use Site.userinfo in favour of Site._userinfo

https://gerrit.wikimedia.org/r/571001

Thanks @Xqt for help as always, patrol.py script works now. Closing task as resolved!

But, I found this in pywikibot-core-tox-publish:

22:56:58 WARNING: autodoc: failed to import module 'gui' from module 'pywikibot.userinterfaces'; the following exception was raised:
22:56:58 No module named '_tkinter', please install the python3-tk package

Change 572484 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Use site.userinfo getter instead of site._userinfo within api

https://gerrit.wikimedia.org/r/572484

Xqt reopened this task as Open.EditedFeb 16 2020, 12:09 PM

Reopened. dry_api_tests.DryWriteAssertTests.test_normal shows a warning now:

C:\pwb\GIT\core>pwb dry_api_tests -v DryWriteAssertTests.test_normal
tests: max_retries reduced from 15 to 1
test_normal (__main__.DryWriteAssertTests)
Test Request object when username is correct. ... WARNING: API write action by unexpected username commenced.
userinfo: {'name': 'myusername', 'groups': []}
ok

----------------------------------------------------------------------
Ran 1 test in 0.003s

OK

Solved with the patch submitted above

Change 572484 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Use site.userinfo getter instead of site._userinfo within api

https://gerrit.wikimedia.org/r/572484