Page MenuHomePhabricator

makecat.py fails under python 3: TypeError: can't concat bytes to str
Closed, ResolvedPublic

Description

$ python3 pwb.py makecat TEST -lang:en -family:wikipedia
Traceback (most recent call last):
  File "pwb.py", line 263, in <module>
    if not main():
  File "pwb.py", line 257, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 121, in run_python_file
    main_mod.__dict__)
  File "./scripts/makecat.py", line 224, in <module>
    'category', workingcatname.encode('ascii', 'xmlcharrefreplace') + '_exclude.txt')
TypeError: can't concat bytes to str
<class 'TypeError'>
CRITICAL: Closing network session.

Details

Related Gerrit Patches:

Event Timeline

Dalba created this task.Apr 19 2017, 4:31 PM
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald TranscriptApr 19 2017, 4:31 PM
Xqt added a subscriber: Xqt.Jul 14 2017, 8:45 PM

the problem is in config2.py.makepath or datafilepath. I think bytestrings are reqired not unicode or these os methods.

Xqt triaged this task as High priority.Jul 14 2017, 8:46 PM

workingcatname.encode('ascii', 'xmlcharrefreplace') + '_exclude.txt')
This is wrong -- workingcatname.encode('ascii', 'xmlcharrefreplace') will create a bytes object, and this cannot be concatenated with the '_exclude.txt' string.

workingcatname.encode('ascii', 'xmlcharrefreplace').decode('ascii') + '_exclude.txt'

should be OK.

Change 365449 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [bugfix] Don't use mixed bytestring and unicode for filename

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

Xqt claimed this task.Jul 15 2017, 12:55 PM

Change 365449 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Don't use mixed bytestring and unicode for filename

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

Xqt closed this task as Resolved.Jul 15 2017, 1:08 PM