所以我得到了这段代码,可以从linux服务器使用python连接到redshift。 它让我sqlalchemy.exc.NoSuchColumnError:“找不到列“0”的行中的列”在尝试从红移服务器获取表时出错。在
其他有类似经验和错误的人通过更新python包解决了这个问题,我今天早些时候做了所有的工作,但是我仍然得到错误。在
版本:
Python 2.7.12版
SQLAlchemy 1.1.6版
sqlalchemy红移0.5.0
心理学2.7
代码如下,我使用控制台登录:
from sqlalchemy import create_engine
import getpass
import json
def getredshiftconnect(console_login=True, login_credentials_file=None):
try:
if console_login:
login = getpass.getpass("Username: ")
password = getpass.getpass("Password: ")
server = input("Server: ")
database = input("Database connecting to: ")
schema = input("Schema connecting to: ")
engine = create_engine("redshift+psycopg2://{0}:{1}@{2}:<PortNumber>/{3}"\
.format(login, password, server, database))
else:
# Read JSON file with login credentials
# Make sure that fields are referenced correctly, i.e.:
# login, password, server, database
login_credentials = json.load(open(login_credentials_file,"r"))
engine = create_engine("redshift+psycopg2://{0}:{1}@{2}:<PortNumber>/{3}"\
.format(login_credentials["login"],
login_credentials["password"],
login_credentials["server"],
login_credentials["database"]))
# To test connection, if able to list tables then login was succesful
# Pick a schema that actually has tables
if engine.table_names(schema): # Explodes at this call
print ("Successfully connected")
return engine
else:
print ("Not properly connected")
except Exception as e:
print ("Error Connecting: ", e)
我确实发现了SQLAlchemy-1.1.6是这个问题的原因。 在降级到1.1.5之后,我的情况又恢复了正常。在
注意:我发现最新版本的SQLAlchemy还有一些bug。 我还不得不在一些服务器上删除并重新安装SQLAlchemy来解决这个问题(例如pip卸载SQLAlchemy)。在
相关问题 更多 >
编程相关推荐