0

mysql.connector.errors.DatabaseError: 1366 (HY000): Incorrect string value: '\x92\x1B\x86\xBD\x8A\x0F...' for column 'Current_Password' at row 1

conn = mysql.connector.connect(user='***', password='***', host='*.*.*.*',database='**',auth_plugin='mysql_native_password')
# Creating a cursor object using the cursor() method
bin_value = b'a\x92\x1b\x86\xbd\x8a\x0f\xce \x1c+\xae1\xcd\x8d\x92'
cursor = conn.cursor()
sql = "INSERT INTO mydb.mycol(ID, Username,Email,Age,Current_Password,Old_Password_1,Old_Password_2,Old_Password_3,Old_Password_4,Old_Password_5,Old_Password_6,Old_Password_7,Old_Password_8,Old_Password_9,Old_Password_10) 
VALUES (%s, %s,%s, %s,%s, %s,%s, %s,%s, %s,%s, %s,%s, %s,%s)"
val = (2333, "nati","test@gmail.cim",55,bin_value ,"1","2","3","4","5","6","7","8","9","10")
cursor.execute(sql,val)
print(cursor.rowcount, "record inserted.")
conn.commit()
conn.close

MY DB

  • 2
    Bytes probably won't work, and you'd need to either change the column type in MySQL to binary or store a string. – mechanical_meat Oct 31 '21 at 22:50
  • 1
    I hope your are using a [secure password method](https://stackoverflow.com/questions/7014953/i-need-to-securely-store-a-username-and-password-in-python-what-are-my-options) and not plain text. While correcting the type, also correct the length to the length of the secure method you use. Using a list of old passwords (of the same incorrect type) in the same table will cause troubles with your queries, put them into a separate table with an `ID` index. Welcome to SO, please use `show create table {tablename}` as text next time, its easier to parse and removes user interface ambiguities. – danblack Nov 01 '21 at 00:29
  • Yes thank you I solve the problem. Need to change the datatype of the column that include the binary password to: VARBINARY(2048) – netanel levi Nov 01 '21 at 16:12

0 Answers0