Error importing Russian characters from csv file

44 views
Skip to first unread message

aabelyakov

unread,
Mar 31, 2020, 5:02:29 AM3/31/20
to web2py-users
When importing data (russian characters) from a .csv-file into a table, an 
error occurs:
<class 'UnicodeDecodeError'> 'ascii' codec can't decode byte 0xd0 in 
position 65: ordinal not in range(128).

Standalone PyDAL works fine!
=============================================================================
import locale 
print('locale.getpreferredencoding(False) =', locale.getpreferredencoding(False))

db.import_from_csv_file(
open('applications/upoweron/databases/csv/all.csv'),
restore=True,
encoding="utf-8",
)

db.commit()
=============================================================================
Result:
locale.getpreferredencoding(False) = ANSI_X3.4-1968

Dave S

unread,
Apr 2, 2020, 7:39:55 PM4/2/20
to web2py-users


On Tuesday, March 31, 2020 at 2:02:29 AM UTC-7, aabelyakov wrote:
When importing data (russian characters) from a .csv-file into a table, an 
error occurs:
<class 'UnicodeDecodeError'> 'ascii' codec can't decode byte 0xd0 in 
position 65: ordinal not in range(128).

When you get this error, are you using appadmin to do the import?   It appears appadmin doesn't specify the encoding, so defaults to ASCII.  In 2.18.5 that's line 177 of [...]\web2py\applications\admin\controllers\appadmin.py.

I'm not sure what the best way is to fix this, but it would be appropriate to file a bug report.




Standalone PyDAL works fine!
=============================================================================
import locale 
print('locale.getpreferredencoding(False) =', locale.getpreferredencoding(False))

db.import_from_csv_file(
open('applications/upoweron/databases/csv/all.csv'),
restore=True,
encoding="utf-8",
)

db.commit()
=============================================================================
Result:
locale.getpreferredencoding(False) = ANSI_X3.4-1968

See, you specified the encoding there.

/dps
 

Dave S

unread,
Apr 2, 2020, 7:44:51 PM4/2/20
to web2py-users
Also, Google Groups doesn't make it clear, but  "always show on top" option for a topic pins the topic, but that should only be used, in the way this group works, for messages that a need to be persistent ... like administrative messages.

/dps
Reply all
Reply to author
Forward
0 new messages