Reputation: 21
So I've got this code to connect to redshift using python from a linux server. It throws me the sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for column '0'" error when I try to get the tables from the redshift server.
Other that have experienced and error similar to this solved it by updating python packages, I did all of mine earlier today but I'm still getting the error.
Versions:
Python 2.7.12
SQLAlchemy 1.1.6
sqlalchemy-redshift 0.5.0
psycopg2 2.7
Here's the code, I'm using the console_login:
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)
Upvotes: 2
Views: 4139
Reputation: 31
I did figure out that SQLAlchemy-1.1.6 is the cause of the issue. After downgrade to 1.1.5 it is working fine again in my case.
pip install SQLAlchemy==1.1.5
Note: I found out that the latest version of SQLAlchemy has some more bugs. Also I had to remove and reinstall SQLAlchemy on some servers to solve the issue (e.g. pip uninstall SQLAlchemy).
Upvotes: 3