аватар question@mail.ru · 01.01.1970 03:00

Coding problem when recording in SQLite3

I write in Windows 7 on Python 2.7.10.

  #-*-coding: utf-8-*- conn = conn = connn = db.connect ( 'main.db' )  #conn.text_Factory = str  c = conn.cursor () c.execte ( 'Pragma Encoding = "UTF-8";' ) c.execute ( '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' ) c.execute (    print   u" "is allowed only the letters are allowed Latin alphabet and numbers " name = raw_input (). Strip ()  #name.decode ('UTF-8')  c.execute ( "" Select Count (Login) From User Where user.login =? "" , (NAME,))     

As far as I know, the format of the lines in SQLite3 has the default UTF-8 encoding. When you try to record the user name in Russian letters in the SQLite3 database, I get an error:

traceback (Most Recent Call Last):
file "" D: /Project/pwd/pwd.py ", line 30, in & lt; module & gt;
c.execute ("" Select Count (Login) from User Were user.login =? "" (NAME,))
SQLITE3.PROGRAMMINGERRORROR : You must not use 8-bit bytestrings you ust_apactory that can integ Bytestrings (Like Text_Factory = Str). It is Highly Recommoded that you Inst, your application to unicode strings. name.Decode ('UTF-8') , then the error is different:

traceback (Most Recent Call Last):
File "" D: /project/pwd.py "" "" Line 29, in & lt; module & gt;
name.Decode ('UTF-8')
File "" C: \ Python27 \ LIB \ ENCODINGS \ UTF_8.PY "", Line 16, In decode

retu.utf_8_decode (Input, errors, True)
unicodecodeeror : 'Utf8' Codec Can 'Canmode by 0xd1 in Position 0: Invalid Continuation by

I deducted that you can use confactory = str , with the base to the base Russian letters are written, but this is not recommended and at the same time the letters have the appearance:

How do I write Russian names into the base so that they look normal at the same time? Typeerror ) in the TRY - Exception structure that arises if the user has entered the wrong phrase with which his password was encrypted to any service:

   try :   print   u'parol \ t- ', aes.Decrypt (I [ 1 ]). Decode ( 'utf-8' )   experept : unicodeedecodeeroror ( u'ne corrective secret The phrase ')     

p.s. I try this:

   print  name.Decode ( 'CP1251' ). ENCODE ( 'utf-8' ). Decode ( 'utf-8' )   

Sergey-i.e. Like everything in UTF-8, but the error is still there:

traceback (Most Recent Call Last):
file "D: /Project/pwd/pwd.py" "" "" "" "" "" "" "" "" & lt; module & gt;
c.execute ("" Select Count (Login) from User Were user.login =? "" (NAME,))

SQLITE3.PROGRAMMINGERRORROR : You must not use 8-bit bytestrings you ust_apactory that can integ Bytestrings (Like Text_Factory = Str). It is Highly Recommoded that you instead just switch your application to unicode strings.

I am trying So:

  Name =    preint  name.Decode ( 'CP1251' ). ENCODE ( 'UTF-8' ). Decode ( 'utf-8' )   

t. e., as it were, everything is in the UTF-8, but the mistake is still there:

traceback (Most Recent Call Last):
File "" D: /Project/pwd/pwd.py "", Line 32, in & lt; module & gt;
c.execute ("" Select Count (Login) from User Were user.login =? "" (NAME,))

SQLITE3.PROGRAMMINGERRORROR : You must not use 8-bit bytestrings you ust_apactory that can integ Bytestrings (Like Text_Factory = Str). It is Highly Recommoded that your inst, your Application to Unicode Strings.

аватар answer@mail.ru · 01.01.1970 03:00

When working with a console, Windows uses CP866 encoding. It is for this reason that an error of coding occurs.

try to translate from CP866 to UTF-8

  name = name.Decode ( 'CP866' ). ENCODE ( 'UTF-8' )                                       

Latest

Similar