Page MenuHomePhabricator

non ascii in system messages and max retry
Closed, DeclinedPublic

Description

Originally from: http://sourceforge.net/p/pywikipediabot/patches/477/
Reported by: lankier
Created on: 2010-10-22 10:26:44
Subject: non ascii in system messages and max retry
Assigned to: xqt
Original description:
This patch fixed two issues:
1\. Ubuntu has non ascii in system messages.

Test:
$ sudo ifconfig eth0 down
$ cat test.py
import wikipedia
site = wikipedia.getSite\(\)
page = wikipedia.Page\(site, 'S'\)
text = page.get\(\)
$ LANG=ru\_RU.utf8 python test.py
Error downloading data: 'ascii' codec can't decode byte 0xd0 in position 27: ordinal not in range\(128\)
Request ru:/w/api.php?inprop=protection%7Ctalkid%7Csubjectid%7Curl%7Creadable&format=json&rvprop=content%7Cids%7Cflags%7Ctimestamp%7Cuser%7Ccomment%7Csize&prop=revisions%7Cinfo&titles=S&rvlimit=1&action=query
Retrying in 1 minutes...
^C

After fix \(added "e = unicode\(str\(e\), locale.getpreferredencoding\(\)\)"\):
$ LANG=ru\_RU.utf8 python test.py
<urlopen error \[Errno 101\] Сеть недоступна>

WARNING: Could not open \[...\]

2\. Added raise MaxTriesExceededError when max tries exceeded.


Version: compat-(1.0)
Severity: normal
See Also:
https://sourceforge.net/p/pywikipediabot/patches/477

Details

Reference
bz54572

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 2:12 AM
bzimport set Reference to bz54572.

We can't fix it in output\(\) because we have an exception before we entered in output\(\).

What about just replace output\(u'%s' %e\) -> output\(str\(e\)\) ? it works.

output should be fixed in output method. Would you please check the following fix in output method:

def output\(...\)
...
try:
text = unicode\(text, 'utf-8'\)
except UnicodeDecodeError:
text = unicode\(text, 'iso8859-1'\)

replace it with

try:
text = unicode\(text, 'utf-8'\)
except UnicodeDecodeError:
text = unicode\(text, locale.getpreferredencoding\(\)\)

I think we should either
a\) skip the entire output\(\) machinery and use traceback.print\_exc\(\) instead
or
b\) write a wrapper for that does what you propose here \(but which can also be used for traceback.format\_exc\).

and replace all exception printing with one of those two options.

housekeeper's note: the patch does not apply cleanly to r10035

Xqt removed Xqt as the assignee of this task.Feb 26 2015, 6:43 PM
Aklapper triaged this task as Lowest priority.Jun 5 2015, 1:41 PM
Aklapper subscribed.

Pywikibot has two versions: Compat and Core. This task was filed about the older version, called Pywikibot-compat, which is not under active development anymore. Hence I'm lowering the priority of this task to reflect the reality. Unfortunately, the Pywikibot team does not have the manpower to retest every single bug report / feature request against the (maintained) Pywikibot code base. Furthermore, the code base of Pywikibot-Compat has changed a lot compared to the code base of Pywikibot-Core so there is a chance that the problem described in this task might not exist anymore. Please help: Unfortunately manpower is limited and does not allow testing every single reported task again. If you have time and interest in Pywikibot, please upgrade to Pywikibot-Core and add a comment to this task if the problem in this task still happens in Pywikibot-Core (or directly edit the task by removing the Pywikibot-compat project and adding the Pywikibot project to this task). To learn more about Pywikibot and to get involved in its development, please check out https://www.mediawiki.org/wiki/Manual:Pywikibot/Development Thank you for your understanding.

Xqt claimed this task.

declined for compat