pymysql TypeError: object supporting the buffer API required

编程入门 行业动态 更新时间:2024-10-09 08:27:41

pymysql TypeError: <a href=https://www.elefans.com/category/jswz/34/1770996.html style=object supporting the buffer API required"/>

pymysql TypeError: object supporting the buffer API required

使用python语言,通过pymysql库访问mysql数据库(别问我为什么不用orm框架,有些时候orm框架真的不如原生态的sql好用),在我本机运行是ok的,但在另一同事机器运行失败,报错如下:

Traceback (most recent call last):File "D:/work//scripts/main.py", line 25, in <module>biz_service.initialize("./config/config.yaml")File "D:\work\\scripts\biz\sync_security_service.py", line 57, in initializepassword=self._config.mysql.password,db=self._config.mysql.database)File "D:\work\scripts\env\lib\site-packages\pymysql\__init__.py", line 94, in Connectreturn Connection(*args, **kwargs)File "D:\work\scripts\env\lib\site-packages\pymysql\connections.py", line 325, in __init__self.connect()File "D:\work\scripts\env\lib\site-packages\pymysql\connections.py", line 599, in connectself._request_authentication()File "D:\work\scripts\env\lib\site-packages\pymysql\connections.py", line 817, in _request_authenticationauthresp = _auth.scramble_native_password(self.password, self.salt)File "D:\work\scripts\env\lib\site-packages\pymysql\_auth.py", line 39, in scramble_native_passwordstage1 = sha1_new(password).digest()File "D:\work\scripts\env\lib\hashlib.py", line 149, in __hash_newreturn _hashlib.new(name, data)
TypeError: object supporting the buffer API required

   开始以为是python版本和pymysql版本的问题,后来换成一样的版本,还是报错!!!!从上面的日志其实可以很清楚的看到错误的函数:sync_security_service.py的第57行(不得不说,详细的错误日志及堆栈是个好东东),而57行就是:

self._connect=pymysql.connect(host=self.mysql.ip,port=self.mysql.port,user=self.mysql.user,password=self.mysql.password,db=self.mysql.database)

于是决定跟踪pymysql.connect函数到底干了什么~~~

在跟踪的过程中,偶然发现:self.mysql.password是一个整型,竟然是一个整型,密码应该是字符串类型,怎么会是整型呢?原来同事的密码是一串数字123456,python在读配置文件过程中默认把123456转成了整型,修改如下:

self._connect=pymysql.connect(host=self.mysql.ip,port=self.mysql.port,user=self.mysql.user,password=str(self.mysql.password),db=self.mysql.database)

再次运行,发现问题解决。

更多推荐

pymysql TypeError: object supporting the buffer API required

本文发布于:2024-03-09 20:08:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1725992.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:object   TypeError   pymysql   supporting   required

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!