我尝试使用这个Python脚本检索从MySQL数据库值:字符串从MySQL返回在Python
import mysql.connector
from mysql.connector import errorcode
config_file = {}
try:
cnx = mysql.connector.connect(<removed.)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exists")
else:
print(err)
else:
cursor = cnx.cursor()
cursor.execute("SELECT config_key, config_value FROM T_ConfigTable")
for (config_key, config_value) in cursor:
print("{}: {}".format(config_key, config_value))
config_file[config_key] = config_value
cursor.close
cnx.close
print(config_file)
但结果总是回来为:
b'value1' :b'value2 '
etc
我该如何摆脱b's?
我使用Python 3.2
感谢您的帮助
使用'SRT(CONFIG_VALUE)'来获取字符串值 – njzk2
这没有按”帮助。同样的结果。 – matzr
它的python3,然后呢? – njzk2