web.py连接mysql错误

发布于 2024-11-09 03:58:39 字数 1446 浏览 2 评论 0原文

当我使用 web.py 连接本地 mysql 时,出现一些错误:

Traceback (most recent call last):
  File "code.py", line 7, in <module>
    db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
  File "/Library/Python/2.6/site-packages/web.py-0.34-py2.6.egg/web/db.py", line 1078, in database
    return _databases[dbn](**params)
  File "/Library/Python/2.6/site-packages/web.py-0.34-py2.6.egg/web/db.py", line 928, in __init__
    import MySQLdb as db
  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
    /Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture

我的 python 代码如下:

import web
render = web.template.render('templates/')
urls = (
    "/(.*)","index"
)
app = web.application(urls,globals())
db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
class index:
    def GET(self):
        todos = db.select('todo')
        return render.index(todos)
if __name__=="__main__":app.run()

我的 python 版本是 2.6.1

我该如何修复它?

谢谢

when i use web.py to connect local mysql, some error show:

Traceback (most recent call last):
  File "code.py", line 7, in <module>
    db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
  File "/Library/Python/2.6/site-packages/web.py-0.34-py2.6.egg/web/db.py", line 1078, in database
    return _databases[dbn](**params)
  File "/Library/Python/2.6/site-packages/web.py-0.34-py2.6.egg/web/db.py", line 928, in __init__
    import MySQLdb as db
  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/__init__.py", line 19, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 7, in <module>
  File "build/bdist.macosx-10.6-universal/egg/_mysql.py", line 6, in __bootstrap__
ImportError: dlopen(/Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so, 2): no suitable image found.  Did find:
    /Users/rlog/.python-eggs/MySQL_python-1.2.3-py2.6-macosx-10.6-universal.egg-tmp/_mysql.so: mach-o, but wrong architecture

my python code like this:

import web
render = web.template.render('templates/')
urls = (
    "/(.*)","index"
)
app = web.application(urls,globals())
db = web.database(dbn='mysql',user='root',pw='123456',db='pytable')
class index:
    def GET(self):
        todos = db.select('todo')
        return render.index(todos)
if __name__=="__main__":app.run()

my python version is 2.6.1

how could i fix it ?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青柠芒果 2024-11-16 03:58:39

您为 Python 安装的 mysql 适配器已损坏或适用于不同的体系结构。我不确定你是如何安装它的(或者这些东西在 OSX 上如何工作)。 这是一个讨论安装的问题。如果你做对了,它应该可以正常工作(假设凭据正确)。

The mysql adaptor you've installed for Python is corrupt or for a different architecture. I'm not sure how you've installed it (or how these things work on OSX). Here's a question that discusses the installation. If you get that right, it should work fine (assuming that the credentials are correct).

樱花落人离去 2024-11-16 03:58:39

db = web.database(dbn='mysql', db='projefg9_emearmy_ps_erc', user='root',
pw='admin')

其中 dbn -- 您正在使用的数据库(对于 mysql,它是“mysql”)
db——数据库名称
user -- 数据库的用户名
pw -- 数据库的密码

db = web.database(dbn='mysql', db='projefg9_emearmy_ps_erc', user='root',
pw='admin')

where dbn -- database you are using (for mysql it is "mysql")
db -- database name
user -- username of your database
pw -- password of your database

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文