赞
踩
我正在用peeweeorm开发一个基于烧瓶的python应用程序。我最初是连接到存储在本地计算机上的数据库,现在我正试图过渡到远程连接数据库。我已经通过服务器的cpanel部分在phpmyadmin中设置了数据库。在
问题
我已将IP地址设置为能够远程访问我的数据库,但当我尝试连接到数据库时遇到以下错误:Traceback (most recent call last):
File "app.py", line 294, in
models.initialize()
File "/Users/wyssuser/Desktop/dscraper/models.py", line 145, in initialize
DATABASE.connect()
File "/Library/Python/2.7/site-packages/peewee.py", line 2767, in connect
self.__local.closed = False
File "/Library/Python/2.7/site-packages/peewee.py", line 2688, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File "/Library/Python/2.7/site-packages/peewee.py", line 2766, in connect
**self.connect_kwargs)
File "/Library/Python/2.7/site-packages/peewee.py", line 3209, in _connect
return mysql.connect(db=database, **conn_kwargs)
File "/Library/Python/2.7/site-packages/pymysql/__init__.py", line 88, in Connect
return Connection(*args, **kwargs)
File "/Library/Python/2.7/site-packages/pymysql/connections.py", line 644, in __init__
self._connect()
File "/Library/Python/2.7/site-packages/pymysql/connections.py", line 869, in _connect
raise exc
peewee.OperationalError: (2003, "Can't connect to MySQL server on '142.157.25.22' ([Errno 61] Connection refused)")
这是我代码中引用数据库连接的部分:
应用程序副本
^{pr2}$
配置.pyDATABASE = {
'db': 'my_dbname',
'host': '142.157.25.22',
'port': 3306,
'user': 'my_username',
'passwd': 'my_pswd',
}
模型.pyfrom peewee import *
import config
DATABASE = MySQLDatabase(config.DATABASE['db'], host=config.DATABASE['host'], port=config.DATABASE['port'], user=config.DATABASE['user'], passwd=config.DATABASE['passwd'])
...all of my models related code
def initialize():
print 'starting db connection'
DATABASE.connect()
print 'connected'
DATABASE.create_tables([Batch, Company, User, Post],safe=True)
DATABASE.close()
我也尝试过作为主机连接到'localhost',但是在这里似乎不起作用,我应该连接到另一个主机吗?在
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。