0

I have string somestr = '‘something’' and I want to insert it to sql via Python using MySQLdb

I am already using somestr.encode('latin-1', 'ignore') to get latin-1 from the text but it always give following error

UnicodeEncodeError: 'latin-1' codec can't encode character '\u2018'

Anyone know how to solve this issue?

1 Answer 1

1

Try to set the charset when you create your database object like this:

db = MySQLdb.connect(host="localhost", user="root", passwd="", db ="foodb", use_unicode=True, charset="utf8")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.