3
cursor.execute('SELECT userid,productid,description from goqii_store_product_rating_log')

Above is the query I am trying to read from MySQL database using python.

Here the Datatype for description column is TEXT.

When I run this I get the following error:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 8: character maps to

How can I overcome this error and read the data smoothly??.

Python Version used : 3.7.3

Regards

FanoFN
  • 6,815
  • 2
  • 13
  • 33
Anoop Nair
  • 35
  • 7
  • I think the question has already been answered here: https://stackoverflow.com/questions/30598350/unicodedecodeerror-charmap-codec-cant-decode-byte-0x8d-in-position-7240-cha – Gaurav Agarwal Dec 26 '19 at 07:02
  • @GauravAgarwal Hello Gaurav,This is basically while reading a csv file right,Here i am directly importing the data through a SQL query how do I handle it then.Can you help me with a code Snippet as I am new to Python – Anoop Nair Dec 26 '19 at 07:05

1 Answers1

4

I think the question has already been answered here:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 7240: character maps to <undefined>

This seems to be an issue that has been caused by encoding differences.

A way to work around this has been pointed out here as well. Hope this helps: How to return str from MySQL using mysql.connector?

Also, you need to provide more details while posting the question such as the connector you used (eg: PyMySQL)

Try something on these lines:

conn = pymysql.connect(host='localhost',
                       user='username',
                       passwd='password',
                       db='database',
                       charset='utf8')
Gaurav Agarwal
  • 611
  • 6
  • 18