简体   繁体   English

连接到AWS RDS后,SQLAlchemy和PyMySQL拒绝连接到``本地主机''

[英]SQLAlchemy and PyMySQL refusing connection to 'localhost' after connecting to AWS RDS

try:
    engine = create_engine('mysql+pymysql:///mysqladmin:***@***.us-west-2.rds.amazonaws.com:3306/peopledb')
    print "Opened database successfully";

except Exception as e:
    print("Error during connection: ", str(e))

print engine.table_names()

I am attempting to use SQLAlchemy and PyMySQL to connect to a database in AWS RDS. 我正在尝试使用SQLAlchemy和PyMySQL连接到AWS RDS中的数据库。 The above code errors on the final line, when I access engine.table_names(). 当我访问engine.table_names()时,以上代码在最后一行出错。 The error I receive is: 我收到的错误是:

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 10061] No connection could be made because the target machine actively refused it)")

Obviously I am not trying to connect to my localhost, I am connecting/connected to a remote host. 显然,我不是在尝试连接到本地主机,而是在连接/连接到远程主机。

Also I was able to successfully connect and access the database using native PyMySQL commands, this issue has to do with SQLAlchemy. 另外,我还能够使用本地PyMySQL命令成功连接和访问数据库,此问题与SQLAlchemy有关。

Thanks in advance! 提前致谢!

Well, I feel dumb. 好吧,我觉得很蠢。

There is an extra forward-slash (/) in my connection string that was ruining it. 我的连接字符串中有一个多余的正斜杠(/)破坏了它。 :( :(

Thanks anyways! 不管怎么说,多谢拉!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM