ubccr / akrr

Application Kernel Remote Runner
5 stars 6 forks source link

Can not push to external DB due to 'latin-1' codec issue #10

Closed weijianwen closed 4 years ago

weijianwen commented 4 years ago

Hi,

The following messages arose when running akrr resource deploy -r mycluster deploy akrr.

Test status:
Task is in active_tasks queue.
Status: ERROR: Can not push to external DB, will try again
Status info:
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/akrr/akrr_task/akrr_task_appker.py", line 666, in push_to_db
    self.push_to_db_raw(cur, self.task_id, time_finished)
  File "/usr/lib/python3.6/site-packages/akrr/akrr_task/akrr_task_appker.py", line 1009, in push_to_db_raw
    taskexeclog_file_content))
  File "/usr/lib64/python3.6/site-packages/MySQLdb/cursors.py", line 234, in execute
    args = tuple(map(db.literal, args))
  File "/usr/lib64/python3.6/site-packages/MySQLdb/connections.py", line 318, in literal
    s = self.escape(o, self.encoders)
  File "/usr/lib64/python3.6/site-packages/MySQLdb/connections.py", line 225, in unicode_literal
    return db.string_literal(str(u).encode(db.encoding))
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 67-71: ordinal not in range(256)

The job scripts have been generated sucessfully on the remote compute nodes, but failed to push to the DB due to encoding issues.

My workaround is to patch /usr/lib/python3.6/site-packages/akrr/db.py, replacing all instances of cur = con.cursor() with the following:

con.set_character_set('utf8')
cur = con.cursor()
cur.execute('SET NAMES utf8;')
cur.execute('SET CHARACTER SET utf8;')
cur.execute('SET character_set_connection=utf8;')
nsimakov commented 4 years ago

Thanks, It have sense to reset defaults to UTF8. I'll add it to code.

nsimakov commented 4 years ago

Added in 0ebecf1c5cb168b3418219d5d202b0a4142a91f0