I'm getting this error message:
UnicodeEncodeError at /new_app/
'charmap' codec can't encode character '\x87' in position 127: character maps to <undefined>
I get data from a query in teradata using pandas and python teradata module. After creating connection, I do this:
In [10]: df = pd.read_sql(sqlStr, self.session)
In [11]: df
Out[11]:
Ref Client Order Group Start Date Item Date Value
0 2020-04-30 01234567890 SECURITIZA�øO 45678901234 1995-11-13 2014-08-23 21031.96
1 2020-04-30 01234567890 SECURITIZA�øO 45678901234 1995-11-13 2014-08-23 21031.96
There is a problem in the word "SECURITIZA�øO".
Then I've tried to do the following:
In [12]: from django.core.files.base import ContentFile
In [13]: from new_app.models import QSet
In [14]: content = df.to_csv(index=False, encoding='utf-8')
In [15]: csvname = "test_name"
In [16]: csf = ContentFile(content, csvname)
In [17]: q = QSet.objects.create(owner = "somebody", csv_file = csf)
Then I got the error above.
This is my model config:
class QSet(models.Model):
date_query = models.DateField(default=now, blank=True, null=True)
owner = models.CharField(max_length=25)
csv_file = models.FileField(blank=True, upload_to='new_app')
And , I don't know if it matters, here are some settings of my project:
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
I am struggling with this error and I think that I am misunderstanding some steps of encoding. I'll appreciate any ideas.