This project is archived and is in readonly mode.
TypeError: can't escape unicode to binary: writing unicode into bytea
-
tamagotchi
After poking around some more, I figure out that the above code doesn't work with other versions of Postgres and psycopg as well.
The reason why my application broke was the upgrade from cherrypy 3.1.x to 3.2 where the data in the request is now passed as unicode objects rather than strings.
The question for me remains still, is it reasonable to expect that byteas/Binaries should work with unicode?
If not, why not? (in which case this bug report would be invalid)Thanks,
-T
-
Daniele Varrazzo
- Tag set to binary, unicode
- State changed from new to invalid
No, it's not reasonable for unicode to be interpreted as a binary string. This is the entire point for which there are separate unicode and string object (or str and bytes in Py3).
Internal unicode representation could be 2 or 4 bytes per codepoint. It can be converted to binary in different ways according to different encoding.
If you want to pass unicode to a binary you will have to convert it to byte string specifying your own encoding. For me it's a bug in cherrypy 3.2.