1

When i use sqlite3 database with sqlalchemy library, i got this error

sqlalchemy.exc.ProgrammingError: (ProgrammingError) 
You must not use 8-bit bytestrings unless you use a text_factory that can
interpret 8-bit bytestrings (like text_factory = str). 
It is highly recommended that you instead just switch your application 
to Unicode strings. 
u'INSERT INTO model_pair (user, password) VALUES (?, ?)' ('\xebE\xc2\xe4.\[email protected]', '123456')

and here is some test data:

 呆呆 [email protected]        11111                                                             
  è?“言    [email protected]        11111 
wwwj55572@gg?€?       11111

I have configured database encoding as utf-8 or gbk but neither success when insert, i try str.decode('gbk'), it will stuck on char like € and get error like above.

anyone tell me how get around this error ?

1

1 Answer 1

3

try to change '\xebE\xc2\xe4.\[email protected]' to u'\xebE\xc2\xe4.\[email protected]'

also, you could try to do '\xebE\xc2\xe4.\[email protected]'.decode("utf-8"), but it gives an error "invalid continuation byte", perhaps your string is not valid utf-8 after all?

btw, do mention is you are running python 2.x or 3.x, there is a difference.

Sign up to request clarification or add additional context in comments.

2 Comments

i use python2.7 and i am trying to insert sql statement, instead of using ORM model to import data. Behide the science cause trouble
did you try u'\x...' or u"\N{EURO SIGN}"?

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.