Xqt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/228620
Change subject: [FIX] Workaround fix for UnicodeEncodeError in api.py
......................................................................
[FIX] Workaround fix for UnicodeEncodeError in api.py
When an api error occures, the error will be written to a log file.
In some cases repr(Page) may fail but it works for Page.title().
Replace page objects with it's title()
Bug: T66958
Bug: T107428
Change-Id: I90ead6682d10e29443b4fae3101e6e3d2332b317
---
M pywikibot/data/api.py
1 file changed, 11 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/20/228620/1
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index d864abf..d82dd39 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -2088,12 +2088,18 @@
for e in user_tokens.items())))
# raise error
try:
- # Due to bug T66958, Page's repr may return non ASCII bytes
- # Get as bytes in PY2 and decode with the console encoding as
+ # Due to bug T66958, Page's repr may fail.
+ # Get page.title() instead,
# the rest should be ASCII anyway.
- param_repr = str(self._params)
- if PY2:
- param_repr = param_repr.decode(config.console_encoding)
+ try:
+ param_repr = repr(self._params)
+ except UnicodeEncodeError:
+ print 'UnicodeError'
+ param_repr = self._params
+ titles = []
+ for item in param_repr['title']:
+ titles.append(item.title())
+ param_repr['title'] = titles
pywikibot.log(u"API Error: query=\n%s"
% pprint.pformat(param_repr))
pywikibot.log(u" response=\n%s"
--
To view, visit https://gerrit.wikimedia.org/r/228620
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I90ead6682d10e29443b4fae3101e6e3d2332b317
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits