【问题标题】:I want to connect to mysql in webpy But I get this error:<type 'exceptions.ImportError'>我想在 webpy 中连接到 mysql 但我收到此错误:<type 'exceptions.ImportError'>
【发布时间】:2014-08-22 19:25:07
【问题描述】:

这是我的代码:

import web    
import MySQLdb
urls = ('/', 'capture')    
app = web.application(urls,globals())    
class capture:    
    def GET(self):    
        db = web.database(dbn='mysql', db='mydata', user='root', pw='123456')           
if __name__ == "__main__":    
        app.run()

我运行它并打开本地主机页面并得到错误:

"&lt;type 'exceptions.ImportError'&gt; at / this is MySQLdb version (1, 2, 4, 'beta', 4), but _mysql is version (1, 2, 3, 'final', 0)"

我们如何解决这个问题。

【问题讨论】:

  • 尝试导入MySQLdb
  • 得到同样的错误:(
  • tanx 我解决了。我有另一个问题。此代码是否创建名称为“mydata”的数据库?还是直接连接到那个数据库?

标签: python web.py


【解决方案1】:

很高兴该链接对您的第二个问题有所帮助

db = web.database(dbn='mysql', db='mydata', user='root', pw='123456')

它只使用给定的credentials 到给定的DataBaseconnects。假定数据库已经创建并且您正在连接该数据库。希望对您有所帮助。

【讨论】:

  • @user3789719 如果您愿意,可以考虑接受答案并点赞.. :-)
猜你喜欢
  • 2021-01-10
  • 2019-07-18
  • 1970-01-01
  • 2021-06-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-08
相关资源
最近更新 更多