[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: mailer.py commit says TypeError: must be unicode, not str

From: Kenneth Porter <shiva_at_sewingwitch.com>
Date: Thu, 01 Feb 2018 10:31:52 -0800

[moving discussion to dev list as I think this is now the correct fix.]

--On Wednesday, January 31, 2018 7:40 PM -0800 Kenneth Porter
<shiva_at_sewingwitch.com> wrote:

> --On Wednesday, January 31, 2018 7:23 PM -0800 Kenneth Porter
> <shiva_at_sewingwitch.com> wrote:
>
>> fp = builtins.open(file, 'w+') # avoid namespace clash with
>> # trimmed-down svn_fs_open()
>
> I'm now thinking the problem is in the open call, and that I'm somehow
> getting a Python 3 open function even though I've got Python 2.7
> installed. Should the mode be 'wb' instead of 'w+'? That would insure
> that the raw data from the Subversion object is getting dumped into the
> temporary fle without interpretation. I don't understand why update
> (denoted by the plus) is wanted. The temp file isn't being read from.

Proposed edit to fs.py: Change 'w+' to 'wb' when copying svn stream object
to temporary file. Update isn't needed, and the code just needs to dump the
raw data into a file for the external diff to access, so no
encoding/decoding should occur. Hence we should open the file in binary
mode. I just tested this edit and it seems to cure the problem.

It looks like this line is the same since it was originally added in
r843330 and hasn't changed in Troy's swig-py3 branch.

>From my initial report in the users list:

<https://svn.haxx.se/users/archive-2018-01/0094.shtml>
<https://svn.haxx.se/users/archive-2018-02/0000.shtml>

I'm using mailer.py in my post-commit hook and it's throwing a Unicode type
error during the diff phase. Digging through the source code, I figured out
that it's happening during the creation of the two temporary files for
diff'ing. Somehow the output file is getting opened in Unicode text mode
but the input source (the Subversion object stream) is a raw byte stream.
The write call fails.

OS: CentOS 7.4
subversion-python-1.7.14-11.el7_4.x86_64
python-2.7.5-58.el7.x86_64
Received on 2018-02-01 19:34:23 CET

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.