我的目的是把图片存进MySQL,错误在变量data,data明明是bytes-like
我的代码
import pymysql
from pymysql.converters import escape_string
from base64 import encodebytes
def link_mysql():
host='localhost'
username='root'
password='123456'
db_name='yang'
connect=pymysql.connect(host=host,user=username,password=password,db=db_name,use_unicode=True)
return connect
with open(r'D:\壁纸\wallhaven-e76pew.png','rb') as fp:
data=fp.read()
print(type(data))
data=escape_string(data)
connect=link_mysql()
corsor=connect.cursor()
sql="""
insert info picture(img) valuse(%s)
"""
corsor.execute(sql,data)
connect.commit()
corsor.close()
connect.close()