Python3, proteus and text files

51 views
Skip to first unread message

Sergi Almacellas Abellana

unread,
Sep 26, 2016, 5:25:36 AM9/26/16
to try...@googlegroups.com
Hi,

I have an scenario where I'm using a wizard which expects a CSV file and
processes it.

On python2 everything is working well, but in python3 I get the
following error:

https://travis-ci.org/trytonspain/trytond-import_csv/jobs/162620003

This is because proteus does only accept bytes or bytearrays for Binary
fields, but in python (both 2 and 3) read returns and str. See:

» python3
Python 3.5.2 (default, Sep 10 2016, 08:21:44)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(open('default.csv').read(), str)
True

Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> isinstance(open('default.csv').read(), str)
True

Am I doing something wrong? Or it's a proteus bug and it should accept
also string values for text files?

Thanks in advance,
--
Sergi Almacellas Abellana
www.koolpi.com
Twitter: @pokoli_srk

Cédric Krier

unread,
Sep 26, 2016, 5:45:04 AM9/26/16
to try...@googlegroups.com
On 2016-09-26 11:25, Sergi Almacellas Abellana wrote:
> On python2 everything is working well, but in python3 I get the following
> error:
>
> https://travis-ci.org/trytonspain/trytond-import_csv/jobs/162620003
>
> This is because proteus does only accept bytes or bytearrays for Binary
> fields, but in python (both 2 and 3) read returns and str. See:
>
> » python3
> Python 3.5.2 (default, Sep 10 2016, 08:21:44)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> isinstance(open('default.csv').read(), str)
> True
>
> Python 2.7.12 (default, Jul 1 2016, 15:12:24)
> [GCC 5.4.0 20160609] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> isinstance(open('default.csv').read(), str)
> True
>
> Am I doing something wrong? Or it's a proteus bug and it should accept also
> string values for text files?

str in Python2 or Python3 is not the same thing.
You must use str in Python2 and bytes in Python3 for Binary field.

--
Cédric Krier - B2CK SPRL
Email/Jabber: cedric...@b2ck.com
Tel: +32 472 54 46 59
Website: http://www.b2ck.com/

Sergi Almacellas Abellana

unread,
Sep 26, 2016, 7:37:35 AM9/26/16
to try...@googlegroups.com
El 26/09/16 a les 11:40, Cédric Krier ha escrit:
> On 2016-09-26 11:25, Sergi Almacellas Abellana wrote:
>> > Am I doing something wrong? Or it's a proteus bug and it should accept also
>> > string values for text files?
> str in Python2 or Python3 is not the same thing.
> You must use str in Python2 and bytes in Python3 for Binary field.
Thanks for your help, I finally manged to make the module work on both
python2 and python3 using the correct objects on both versions.
Reply all
Reply to author
Forward
0 new messages