Opened 7 years ago

Closed 7 years ago

#5365 closed defect (duplicate)

pysqlite do not accept "strings" from GnuPG

Reported by: steelman Owned by:
Priority: high Milestone: 0.12.2
Component: chat Version: 0.12.1
Severity: normal Keywords: patch
Cc: Blocked By:
Blocking: OS: All


Few days ago Gajim started to drop some messages from my friend. What was really strange was that only his messages have been dropped. It's happened so because he was the only who wrote me in Polish (using some diacritics) and encrypted it with GnuPG. Tracebacks lookt like this like this:

Traceback (most recent call last):
  File "", line 449, in _process_events
    return self.process_events(fd, flags)
  File "/usr/lib64/python2.6/site-packages/gajim/common/xmpp/", line 132, in process_event
  File "/usr/lib64/python2.6/site-packages/gajim/common/xmpp/", line 352, in pollin
  File "/usr/lib64/python2.6/site-packages/gajim/common/xmpp/", line 502, in _do_recei
  File "/usr/lib64/python2.6/site-packages/gajim/common/xmpp/", line 359, in dispatch
  File "/usr/lib64/python2.6/site-packages/gajim/common/", line 1825, in _messag
    session.received(frm, msgtxt, tim, encrypted, msg)
  File "/usr/lib64/python2.6/site-packages/gajim/", line 121, in received
    msgtxt, tim=tim, subject=subject)
  File "/usr/lib64/python2.6/site-packages/gajim/common/", line 476, in write
    return self.commit_to_db(values, write_unread)
  File "/usr/lib64/python2.6/site-packages/gajim/common/", line 342, in commit_to_db
    raise exceptions.DatabaseMalformed 
common.exceptions.DatabaseMalformed: Baza danych nie może zostać odczytana. (pol. Database cannot be read)

After I've had removed except/raise I received a bit more verbose message at the bottom:

sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can in
terpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just sw
itch your application to Unicode strings.

This originated at pysqlite_statement_bind_parameter where a type of a parameter is checked. pysqlite rises exception when the parameter is a string and contains bytes >= 0x80. This occurs when Gajim tries to log a decrypted message that contains unicode charaters and came from GnuPG because GnuPG.decrypt returns a string not a unicode.

The most obvious solution is to call unicode() before returning the decrypted message. However, I am not sure about the encodig. On the other hand it SHOULD or even MUST be UTF-8 since it is XMPP. So my guess is to change to

	return unicode(output, "UTF-8")

It worked for me.

PS. Let the above be my patch and let me refrain from installing yet another VC toolbox ;-)

Change History (1)

comment:1 Changed 7 years ago by asterix

  • Milestone set to 0.12.2
  • Resolution set to duplicate
  • Status changed from new to closed

Thanks for the analyse and the solution, but this has already been fixed in 0.12.2 release. see #4788

Note: See TracTickets for help on using tickets.