Page MenuHomePhabricator

pywikibot.APIError's data should be string, not <unprintable UnicodeMixin object>
Closed, ResolvedPublic

Description

There was an APIError:

[2016-01-27 14:30:49,872: VERBOSE/Worker-13] Submitting unthrottled action 'upload'.
[2016-01-27 14:30:50,133: INFO/Worker-13] Starting new HTTPS connection (2): commons.wikimedia.org
[2016-01-27 14:30:50,365: WARNING/Worker-13] API error stashedfilenotfound: Could not find the file in the stash: key '13rk<REDACTED>sw.myace5.1.webm' not found in stash
[2016-01-27 14:30:50,366: VERBOSE/Worker-13] API Error: query=
u"{u'ignorewarnings': [False], u'maxlag': ['5'], u'format': [u'json'], u'filekey': [u'13rk<REDACTED>sw.myace5.1.webm'], u'stash': [True], u'filename': [u'Izzat (1937) - Full Movie.webm'], u'assert': [u'user'], u'token': [u'7ab3e90c848<REDACTED>+\\\\'], u'filesize': [269407461], u'offset': [268435456], u'action': [u'upload']}"
[2016-01-27 14:30:50,366: VERBOSE/Worker-13]            response=
{u'servedby': u'mw1134', u'error': {u'info': u"Could not find the file in the stash: key '13rk<REDACTED>sw.myace5.1.webm' not found in stash", u'code': u'stashedfilenotfound', u'help': u'See https://commons.wikimedia.org/w/api.php for API usage'}}
[2016-01-27 14:30:50,378: ERROR/MainProcess] Task worker.main[91b7719e-f411-4751-8af7-603b33273dab] raised unexpected: <pywikibot.tools.UnicodeMixin object at 0x7fc58e24aa90>
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/srv/v2c/backend/worker.py", line 77, in main
    filename, wikifileurl = upload.upload(file, filename, url, fileurl, filedesc, username, statuscallback, errorcallback)
  File "/srv/v2c/backend/upload/__init__.py", line 38, in upload
    if site.upload(page, source_filename=filename, comment=comment, text=filedesc, chunk_size=chunked):
  File "/usr/local/lib/python2.7/dist-packages/pywikibot-2.0rc1.post2-py2.7.egg/pywikibot/tools/__init__.py", line 1327, in wrapper
    return obj(*__args, **__kw)
  File "/usr/local/lib/python2.7/dist-packages/pywikibot-2.0rc1.post2-py2.7.egg/pywikibot/site.py", line 5791, in upload
    raise error
APIError: <unprintable UnicodeMixin object>

The last line is clearly unusual, having <unprintable UnicodeMixin object> and caused problems while de-pickling:

Traceback (most recent call last):
  File "/data/project/video2commons/www/python/venv/local/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/data/project/video2commons/www/python/venv/local/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/data/project/video2commons/www/python/src/app.py", line 115, in status
    if res.state == 'PENDING':
  File "/data/project/video2commons/www/python/venv/local/lib/python2.7/site-packages/celery/result.py", line 394, in state
    return self._get_task_meta()['status']
  File "/data/project/video2commons/www/python/venv/local/lib/python2.7/site-packages/celery/result.py", line 339, in _get_task_meta
    return self._maybe_set_cache(self.backend.get_task_meta(self.id))
  File "/data/project/video2commons/www/python/venv/local/lib/python2.7/site-packages/celery/backends/base.py", line 295, in get_task_meta
    meta = self._get_task_meta_for(task_id)
  File "/data/project/video2commons/www/python/venv/local/lib/python2.7/site-packages/celery/backends/base.py", line 509, in _get_task_meta_for
    return self.decode_result(meta)
  File "/data/project/video2commons/www/python/venv/local/lib/python2.7/site-packages/celery/backends/base.py", line 192, in decode_result
    return self.meta_from_decoded(self.decode(payload))
  File "/data/project/video2commons/www/python/venv/local/lib/python2.7/site-packages/celery/backends/base.py", line 188, in meta_from_decoded
    meta['result'] = self.exception_to_python(meta['result'])
  File "/data/project/video2commons/www/python/venv/local/lib/python2.7/site-packages/celery/backends/base.py", line 171, in exception_to_python
    from_utf8(exc['exc_type']), __name__)(exc['exc_message'])
TypeError: 'UnicodeMixin' object has no attribute '__getitem__'

Event Timeline

zhuyifei1999 raised the priority of this task from to Needs Triage.
zhuyifei1999 updated the task description. (Show Details)
zhuyifei1999 added subscribers: zhuyifei1999, Yann.

The only way the last line could have been executed, is that the unpickled exception is not an instance of BaseException: (http://docs.celeryproject.org/en/latest/_modules/celery/backends/base.html#BaseBackend.exception_to_python)

Ipatrol subscribed.

The cause of the unprintable error problem appears to be that exceptions.error contains the UnicodeMixin class to provide forward compatibility, but it can cause this mangling when one is using a terminal that is not classified as supporting UTF-8 (see http://bugs.python.org/issue8313).

I can write a patch which would add a __repr__() method to the exception, which I will do so shortly, unless someone thinks the problem is something else.

Xqt triaged this task as High priority.Feb 25 2016, 5:01 AM
Xqt added a subscriber: jayvdb.
Xqt claimed this task.
Xqt subscribed.

UnicodeMixin was removed