mysql-python fetchrow 带来: TypeError: 'long'对象不可调用
我得到了一张桌子:
+-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | Benutzer | varchar(50) | YES | | NULL | | | Confirmed | tinyint(1) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+
只有一个条目!
如果我在 shell 中的 mysql 控制台上执行:
select Benutzer from UserConfirm where Benutzer = '\{\'gid\'\:\ \'tamer\'\,\ \'uid\'\:\ \'tamer\'\}'
它可以工作!
在 mysql-python 出现错误消息:
TypeError: 'long' object is not callable
我做错了什么?! 这是我的 python 代码:
cursor = self.__db.cursor().execute('select * from UserConfirm where Benutzer = \'' + ds + '\'')
return cursor().fetchrow()
如有任何建议,我将非常感谢。
I got a table:
+-----------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+-------+ | Benutzer | varchar(50) | YES | | NULL | | | Confirmed | tinyint(1) | YES | | NULL | | +-----------+-------------+------+-----+---------+-------+
with one entry!
If I execute on the mysql console in a shell:
select Benutzer from UserConfirm where Benutzer = '\{\'gid\'\:\ \'tamer\'\,\ \'uid\'\:\ \'tamer\'\}'
it works!
At mysql-python there comes the errormessage:
TypeError: 'long' object is not callable
What did I make wrong?!
Here is my python code:
cursor = self.__db.cursor().execute('select * from UserConfirm where Benutzer = \'' + ds + '\'')
return cursor().fetchrow()
For any advice, I would kindly thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您没有存储游标对象,只是存储了execute的返回值,这不是游标,它应该是:
The problem is that you are not storing the cursor object, just the return value of execute, which is not the cursor, it should be:
请注意,我假设您的行
cursor().fetchrow()
是一个拼写错误,您的意思是cursor.fetchrow()
。我自己不了解 mysql-python,从错误中我可以假设 Cursor.execute 返回的是行数或错误代码,而不是游标本身。
请尝试以下方法:
Note that I assume your line
cursor().fetchrow()
is a typo and you meantcursor.fetchrow()
.Not knowing mysql-python myself, from the error I can assume
cursor.execute
is returning the number of rows or an error code, not the cursor itself.Try the following instead: