Bugs item #3092329, was opened at 2010-10-21 21:26 Message generated for change (Comment added) made by xqt You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=603138&aid=3092329...
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None
Status: Closed Resolution: Fixed
Priority: 5 Private: No Submitted By: Dr. Trigon (drtrigon) Assigned to: xqt (xqt) Summary: KeyError in userlib.User.contributions
Initial Comment: Hello all
This error occured to me during a try to get contributions of user IWorld:
Traceback (most recent call last): File "sum_disc.py", line 1288, in <module> main() File "sum_disc.py", line 1284, in main bot.run() File "sum_disc.py", line 341, in run self.checkRecentEdits() File "sum_disc.py", line 566, in checkRecentEdits usersumList = [p[0].title() for p in self._user.contributions(limit = count)] File "/data/toolserver/pywikipedia/userlib.py", line 299, in contributions contrib['revid'], ts, contrib['comment'] KeyError: 'comment'
The content of contrib:
{u'pageid': 5698070, u'title': u'Wikipedia:Vandalismusmeldung', u'timestamp': u'2010-10-20T11:58:45Z', u'revid': 80498587, u'user': u'IWorld', u'ns': 4, u'commenthidden': u''}
As you can see the 'comment' item is missing, but a 'commenthidden' is present. I wrote a patch to take this into account. I decided to return an u'' instead of contrib['comment'] in such a case, since in this place an unicode string is expected and thus a None or drop this item is not a good idea.
Please have a look to the attached patch.
Greetings!
----------------------------------------------------------------------
Comment By: xqt (xqt)
Date: 2010-11-06 04:17
Message: KeyError fixed in r8701 as recommended
Maybe there are follow-ups of this bug in other scripts depending of the comment is None
----------------------------------------------------------------------
Comment By: Merlijn S. van Deen (valhallasw) Date: 2010-11-04 14:44
Message: I disagree with the statement "an unicode string is expected and thus a None (..) is not a good idea". The comment is hidden, which is different from an empty comment. Using None is much more sensible.
In addition, the code can be simplified by using contrib.get('comment', None) instead of the current if/the.
----------------------------------------------------------------------
Comment By: Dr. Trigon (drtrigon) Date: 2010-11-04 14:06
Message: I've taken the liberty of assigning this to you.
Should not be a big deal, but would be kind if it would be possible to solve this... ;)
Thanks a lot!
----------------------------------------------------------------------
Comment By: Dr. Trigon (drtrigon) Date: 2010-10-28 10:28
Message: Also issued as:
'KeyError in userlib.User.contributions - ID: 3097185' https://sourceforge.net/tracker/?func=detail&aid=3097185&group_id=93...
sorry for this mess - but I'm not sure which is the better place to rise this issue...
----------------------------------------------------------------------
Comment By: Dr. Trigon (drtrigon) Date: 2010-10-21 21:27
Message: Sorry I forgot this info:
Pywikipedia [https] svn.toolserver.org/svnroot/drtrigon/pywikipedia (r40, 2010/10/02, 22:14:39) Python 2.6.4 (r264:75706, Jun 4 2010, 18:20:31) [GCC 4.4.4 20100503 (Red Hat 4.4.4-2)] config-settings: use_api = True use_api_login = True
----------------------------------------------------------------------
You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=603138&aid=3092329...
pywikipedia-bugs@lists.wikimedia.org