Robin Robin - 4 years ago 190
SQL Question

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/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

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download