PyMySQL / mysqlclient

MySQL/MariaDB connector for Python
https://mysqlclient.readthedocs.io/
GNU General Public License v2.0
2.44k stars 434 forks source link

Bug in python 3.6 version, Byteconversion #444

Closed Kamhamea closed 3 years ago

Kamhamea commented 3 years ago

MySQLdb/__init__.py

Line 122-123

def Binary(x):
     return bytes(x, encoding='utf-8')

With "return bytes(x)" an exception is created

Bye

Kamhamea commented 3 years ago

Sorry return bytes(x, encoding='utf8')

domielias commented 3 years ago

@Kamhamea Hi, do you have a example of how to implement this? I'm reading the documentation but i don't get it. If you can give me you telegram or discord?

Kamhamea commented 3 years ago

This line is just a remnant of Py2 code that nobody noticed yet. It has to be translated into Py3. See here.

This function is only called if you want to store a string in a BinaryField in django which rarely happens.

Kamhamea commented 3 years ago

Sorry I just noticed that the file namis not correctly displayed in my first notice. It is about this file line 123.

methane commented 3 years ago

This function is only called if you want to store a string in a BinaryField in django which rarely happens.

You can not store text in binary field. You need to convert text into binary with txt.encode().