[web2py] db.export_from_csv_file in python3

133 views
Skip to first unread message

Mamisoa Andriantafika

unread,
Oct 13, 2019, 1:05:58 PM10/13/19
to web...@googlegroups.com
Hi,

I can't seem to export the db using db.export_from_csv_file in python3. It is working in python 2.

It seems to be a problem with one of the image or blob field in a table ? Actually there is only on blob field populated with a b64 image file, but yet no image file in upload field.

db.define_table('photo_id',
    Field('imagefile', 'upload'),
    Field('b64img','blob'),
    Field('id_auth_user', 'reference auth_user', writable = False, readable = False),
    auth.signature)

Billet d'erreur for "ECapp19"

Identifiant du Billet

127.0.0.1.2019-10-13.18-48-04.b589bcc3-5676-49ce-a64e-a9b005d108b1

<class 'TypeError'> a bytes-like object is required, not 'str'

Version

web2py™ Version 2.18.5-stable+timestamp.2019.04.08.04.22.03
Python Python 3.6.8: /usr/bin/python3 (prefix: /usr)

Traceback

1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
Traceback (most recent call last):
File "/home/www-data/web2py/gluon/restricted.py", line 219, in restricted
exec(ccode, environment)
File "/home/www-data/web2py/applications/ECapp19/controllers/manage.py", line 135, in <module>
File "/home/www-data/web2py/gluon/globals.py", line 421, in <lambda>
self._caller = lambda f: f()
File "/home/www-data/web2py/applications/ECapp19/controllers/manage.py", line 47, in save_db
db.export_to_csv_file(dumpfile)
File "/home/www-data/web2py/gluon/packages/dal/pydal/base.py", line 852, in export_to_csv_file
ofile, *args, **kwargs)
File "/home/www-data/web2py/gluon/packages/dal/pydal/objects.py", line 2811, in export_to_csv_file
value = base64.b64encode(value)
File "/usr/lib/python3.6/base64.py", line 58, in b64encode
encoded = binascii.b2a_base64(s, newline=False)
TypeError: a bytes-like object is required, not 'str'

Error snapshot help

TypeError(a bytes-like object is required, not 'str')

inspect attributes

Frames

  • File /home/www-data/web2py/gluon/restricted.py in restricted at line 219 code arguments variables

  • File /home/www-data/web2py/applications/ECapp19/controllers/manage.py in <module> at line 135 code arguments variables

  • File /home/www-data/web2py/gluon/globals.py in <lambda> at line 421 code arguments variables

  • File /home/www-data/web2py/applications/ECapp19/controllers/manage.py in save_db at line 47 code arguments variables

  • File /home/www-data/web2py/gluon/packages/dal/pydal/base.py in export_to_csv_file at line 852 code arguments variables

  • File /home/www-data/web2py/gluon/packages/dal/pydal/objects.py in export_to_csv_file at line 2811 code arguments variables

  • File /usr/lib/python3.6/base64.py in b64encode at line 58 code arguments variables

    Function argument list

    (s='data:image/jpeg;base64,/9j/4AAQSkZJRgABAgEBLAEsA...xIWdmOeSSeTn/AOvSJnOM8j9KcWyMjgU5DgHuakVjjgV//9k=', altchars=None)

    Code listing
    53.
    54.
    55.
    56.
    57.
    58.
    59.
    60.
    61.
    62.

    Optional altchars should be a byte string of length 2 which specifies an
    alternative alphabet for the '+' and '/' characters. This allows an
    application to e.g. generate url or filesystem safe Base64 strings.
    """
    encoded = binascii.b2a_base64(s, newline=False)
    if altchars is not None:
    assert len(altchars) == 2, repr(altchars)
    return encoded.translate(bytes.maketrans(b'+/', altchars))
    return encoded
    Variables
    encoded undefined
    global binascii <module 'binascii' (built-in)>
    binascii.b2a_base64 <built-in function b2a_base64>
    s 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAgEBLAEsA...xIWdmOeSSeTn/AOvSJnOM8j9KcWyMjgU5DgHuakVjjgV//9k='
    newline undefined

Any ideas?

Mamisoa

Mamisoa Andriantafika

unread,
Oct 14, 2019, 4:54:41 AM10/14/19
to web2py-users
It seems to be related with the "blob" type where python 2 accept also string type while python 3 expect byte type.

When I delete the row which contains the blob with string inside, exporting function works.

Le dimanche 13 octobre 2019 19:05:58 UTC+2, Mamisoa Andriantafika a écrit :
Hi,

I can't seem to export the db using db.import_from_csv_file in python3. It is working in python 2.

Massimo Di Pierro

unread,
Oct 16, 2019, 2:45:09 AM10/16/19
to web2py-users
Can you please open a pydal ticket? I can fix this over the week-end.

Mamisoa Andriantafika

unread,
Oct 17, 2019, 5:14:47 PM10/17/19
to web2py-users
Reply all
Reply to author
Forward
0 new messages