开发者

web.py connect to mysql error

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/sit开发者_如何学Ce-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


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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜