UnicodeDecodeError on some queries

Bug #274969 reported by Ilan Volow
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
pg8000
Incomplete
Undecided
Unassigned
Ubuntu
Invalid
Undecided
Unassigned

Bug Description

During certain queries for unknown reasons (unknown because I haven't taken much time to investigate why some queries work fine) I get UnicodeDecodeError errors on line 120 in protocol.py (in Parse class' serialize() method) when the query string happens to be in unicode.

Here's the stack trace
  File "tabletest.py", line 17, in <module>
    tColumns = table.all_columns()
  File "/Library/Python/2.5/site-packages/pgub/schema/PGTable.py", line 22, in all_columns
    return self.manager.get_all_table_columns(self.table_name)
  File "/Library/Python/2.5/site-packages/pgub/managers/PGTableManager.py", line 26, in get_all_table_columns
    cursor.execute(queryString)
  File "/Library/Python/2.5/site-packages/pg8000/dbapi.py", line 304, in execute
    self._execute(operation, args)
  File "/Library/Python/2.5/site-packages/pg8000/dbapi.py", line 309, in _execute
    self.cursor.execute(new_query, *new_args)
  File "/Library/Python/2.5/site-packages/pg8000/interface.py", line 297, in execute
    self._stmt = PreparedStatement(self.connection, query, statement_name="", *[{"type": type(x), "value": x} for x in args])
  File "/Library/Python/2.5/site-packages/pg8000/interface.py", line 98, in __init__
    self._parse_row_desc = self.c.parse(self._statement_name, statement, types)
  File "/Library/Python/2.5/site-packages/pg8000/protocol.py", line 857, in _fn
    return fn(self, *args, **kwargs)
  File "/Library/Python/2.5/site-packages/pg8000/protocol.py", line 986, in parse
    self._send(Parse(statement, qs, param_types))
  File "/Library/Python/2.5/site-packages/pg8000/protocol.py", line 906, in _send
    data = msg.serialize()
  File "/Library/Python/2.5/site-packages/pg8000/protocol.py", line 120, in serialize
    val = struct.pack("!i", len(val) + 4) + val
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 3: ordinal not in range(128)

I solved this problem by changing line 112 of protocol.py to the following:

val = self.ps + "\x00" + self.qs.encode("ascii") + "\x00"

I'm running OS X 10.5.4 Leopard, so this may not have appeared on other platforms.

Revision history for this message
Philip Muškovac (yofel) wrote :

This doesn't seem to be an Ubuntu issue.

Changed in ubuntu:
status: New → Invalid
Revision history for this message
Mariano Reingart (reingart) wrote :

I've made a maintenance fork:

http://code.google.com/p/pg8000/

Could you test the latest version?

Several unicode issues were fixed.
If the error persist, please could you report it in the googlecode project issues?
(some data to build a unittest would be great)

Changed in pg8000:
status: New → Incomplete
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.