'Can´t connecto to SAP Hana with sqlalchemy in python
So I´m trying to do a simple connection from Python to SAP HANA with SQLAlchemy but I´m gettin this error:

While my code looks like this:
from sqlalchemy import create_engine, select, Column, Integer, String, Float, Sequence, text
from sqlalchemy.orm import declarative_base, Session, sessionmaker
engine = engine = create_engine('hana+hdbcli:///username:password@host/tenant_db_name', echo=True, future=True)
print("connected")
with engine.connect() as conn:
result = conn.execute(text("select 'hello world'"))
print(result.all())
The error is giving me is correct, I do not have my tenant database in the 30013, I have it in 32015.
How do I fix this?
Solution 1:[1]
I actually managed to connect succesfully later that day and this is my structure (I´m using a tenant db):
db_connection = "hana+hdbcli://Username:Password@Host:port/tennat_db_name"
Thanks in regard!
Solution 2:[2]
You can give the port directly in the connection string. The connection string, that I am using, typically looks something like this:
connection_string = 'hana://%s:%s@%s:%s' % (hdb_user, hdb_password, hdb_host, hdb_port)
You can find usage examples in this and this Jupyter Notebook. Further information can be found in the documentation of the SQLAlchemy HANA dialect.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Diego |
| Solution 2 | Mathias Kemeter |
