Note that there are some explanatory texts on larger screens.

plurals
  1. POEncoding error with sqlalchemy and postgresql
    primarykey
    data
    text
    <p>I'm using pyramid for a web application with a postgres database, wtforms, sqlalchemy and jinja2 and I'm having this error when the application try to get the issues types from database to fill a select field with wtforms:</p> <pre><code>Error: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128) </code></pre> <p>this is the issue types table into model.py:</p> <pre><code>class Mixin(object): id = Column(Integer, primary_key=True, autoincrement=True) created = Column(DateTime()) modified = Column(DateTime()) __table_args__ = { 'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8' } __mapper_args__ = {'extension': BaseExtension()} class IssueType(Mixin, Base): __tablename__ = "ma_issue_types" name = Column(Unicode(40), nullable=False) def __init__(self, name): self.name = name </code></pre> <p>Into bd I have this:</p> <pre><code># select name from ma_issue_types where id = 3; name ------------ Teléfono </code></pre> <p>this is the part where the error occurs</p> <pre><code># -*- coding: utf-8 -*- from issuemall.models import DBSession, IssueType class IssueTypeDao(object): def getAll(self): dbsession = DBSession() return dbsession.query(IssueType).all() #HERE THROWS THE ERROR </code></pre> <p>this is the Traceback</p> <pre><code>Traceback (most recent call last): File "/issueMall/issuemall/controller/issueRegisterController.py", line 16, in issue_register form = IssueRegisterForm(request.POST) File "/env/lib/python2.7/site-packages/wtforms/form.py", line 178, in __call__ return type.__call__(cls, *args, **kwargs) File "/env/lib/python2.7/site-packages/wtforms/form.py", line 224, in __init__ super(Form, self).__init__(self._unbound_fields, prefix=prefix) File "/env/lib/python2.7/site-packages/wtforms/form.py", line 39, in __init__ field = unbound_field.bind(form=self, name=name, prefix=prefix, translations=translations) File "/env/lib/python2.7/site-packages/wtforms/fields/core.py", line 301, in bind return self.field_class(_form=form, _prefix=prefix, _name=name, _translations=translations, *self.args, **dict(self.kwargs, **kwargs)) File "/issueMall/issuemall/form/generalForm.py", line 11, in __init__ types = issueTypeDao.getAll() File "/issueMall/issuemall/dao/master/issueTypeDao.py", line 11, in getAll return self.__dbsession.query(IssueType).all() File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/query.py", line 2115, in all return list(self) File "build/bdist.linux-x86_64/egg/sqlalchemy/orm/query.py", line 2341, in instances fetch = cursor.fetchall() File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 3205, in fetchall l = self.process_rows(self._fetchall_impl()) File "build/bdist.linux-x86_64/egg/sqlalchemy/engine/base.py", line 3172, in _fetchall_impl return self.cursor.fetchall() UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 5: ordinal not in range(128) </code></pre> <p>I try this, but it did not work <a href="http://community.webfaction.com/questions/2609/ascii-as-default-encoding-in-python" rel="nofollow noreferrer">ascii as default encoding in python</a></p> <p>and I try something like this, but it did not work</p> <p><a href="https://stackoverflow.com/questions/11789770/gae-python-ascii-codec-cant-decode-byte">gae python ascii codec cant decode byte</a></p> <pre><code>return dbsession.query(IssueType.id, IssueType.name.encode('utf-8')).all() #or decode('utf-8') </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload