Hi Jake!<div><br></div><div>I think that your attribute is defined with "str" type. Because of this, Pony returns an attribute value in Python as str and not as unicode. By default a str attribute values are represented using latin-1 encoding. And the actual value stored in the database cannot be represented in latin-1 encoding in your case.<br>
<br>To solve your problem in the current version of Pony you should use unicode attribute type instead of str. With unicode type you will get actual unicode value from the database without any re-encoding.</div><div><br></div>
<div>Pony ORM future release 0.6 will support Python 3. Starting this release, str attributes will behave exactly as current unicode attributes, because in Python 3 str type is equivalent to Python 2 unicode type (and we want to make source-compatible entity definitions for Python 2 and Python 3). Starting with Pony ORM 0.6 str and unicode types in attribute definition will mean the same. But currently they behave differently, and unicode type is what you need in your case.<br>
<br>Regards,</div><div>Alexander Kozlovsky</div><div><br></div><div><br>On Sunday, August 17, 2014, Jake Austwick <<a href="mailto:jake@serpiq.com">jake@serpiq.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

                <div>Hey,</div><div><br></div><div>I am trying to store some data that I'm scraping with Scrapy in MySQL, usually I use Postgres however not available this time due to client requirements.</div><div><br>
</div><div>The error I'm receiving is:</div><div><div>File "/Library/Python/2.7/site-packages/pony/orm/core.py", line 1263, in check</div><div><span style="white-space:pre-wrap">      </span>    else: return converter.validate(val)</div>
<div><span style="white-space:pre-wrap">  </span>  File "/Library/Python/2.7/site-packages/pony/orm/dbapiprovider.py", line 387, in validate</div><div><span style="white-space:pre-wrap">   </span>    elif isinstance(val, unicode): val = val.encode(converter.encoding)</div>
<div><span style="white-space:pre-wrap">  </span>exceptions.UnicodeEncodeError: 'latin-1' codec can't encode character u'\u2019' in position 1001: ordinal not in range(256)</div></div><div><br></div><div>
However I'm unsure why it's trying to encode as latin-1, I've tried everything to try and get rid of it:</div><div><br></div><div><ul><li>My MYSQL database and columns are set to UTF8</li><li>I have the following at the top of my python file:</li>
</ul></div><div><br></div><div>import sys</div><div><div>reload(sys);</div><div>sys.setdefaultencoding("utf8")</div></div><div><br></div><div><ul><li>I'm creating my DB connection like this:</li></ul><div><div>
db = Database('mysql', db="xxx", user="root", charset='utf8', use_unicode=True)</div></div></div><div><br></div><div>Was wondering if you had any insight on the issue?</div><div><br></div>
<div>Thanks,</div><div><div>-- </div><div>Jake Austwick</div><div></div><div></div></div>
            </blockquote></div>