[Sqlalchemy-tickets] Issue #3692: Python3 attempting to query db with string gives "TypeError: stri
Brought to you by:
zzzeek
From: Gregory R. <iss...@bi...> - 2016-04-08 22:08:42
|
New issue 3692: Python3 attempting to query db with string gives "TypeError: string argument without an encoding" https://bitbucket.org/zzzeek/sqlalchemy/issues/3692/python3-attempting-to-query-db-with-string Gregory Rehm: My code is pretty straightforward: I'm looking for an entry with an email address. committed_message = Table.query.filter( Table.email_to == email_to ).order_by(Table.created_at.desc()).first() But I get this in response. File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site-packages/sqlalchemy/orm/query.py", line 2634, in first ret = list(self[0:1]) File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site-packages/sqlalchemy/orm/query.py", line 2457, in __getitem__ return list(res) File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site-packages/sqlalchemy/orm/loading.py", line 86, in instances util.raise_from_cause(err) File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 200, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=cause) File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site-packages/sqlalchemy/util/compat.py", line 184, in reraise raise value File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site-packages/sqlalchemy/orm/loading.py", line 71, in instances rows = [proc(row) for row in fetch] File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site-packages/sqlalchemy/orm/loading.py", line 71, in <listcomp> rows = [proc(row) for row in fetch] File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site-packages/sqlalchemy/orm/loading.py", line 457, in _instance unloaded, populators) File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site- packages/sqlalchemy/orm/loading.py", line 520, in _populate_partial dict_[key] = getter(row) File "/Users/greg/workspace/python/meg-server/venv/lib/python3.5/site-packages/sqlalchemy/sql/sqltypes.py", line 859, in process value = bytes(value) TypeError: string argument without an encoding It seems like the problem here is a generic one; when I try to feed bytes() a string argument in Python3 it wants an encoding like utf8 So this would fail bytes("foo") While this is ok bytes("foo", "utf8") |