Deepika reddy
Deepika reddy

Reputation: 95

SQLAlchemy : DatabaseError: (snowflake.connector.errors.DatabaseError) 250001 (08001): Incorrect username or password was specified

DatabaseError: (snowflake.connector.errors.DatabaseError) 250001 (08001): Failed to connect to DB: ****.us-east-1.snowflakecomputing.com:443. Incorrect username or password was specified.

I got the above error when I tried to connect to snowflake using sqlalchemy . My credentials has @ . So I tried using urllib.parse . Still it is not able to connect

Below is the code I used

import pandas as pd
import snowflake.connector
#from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.dialects import registry

registry.register('snowflake', 'snowflake.sqlalchemy', 'dialect')


# Establish the connection to the Snowflake database
snowflake_user = 'my_name.last@****.com'
snowflake_password = 'password@123'
snowflake_account = '****.us-east-1'
snowflake_client_prefetch_threads = 4

sf = 'snowflake://{}:{}@{}'.format(snowflake_user, snowflake_password, snowflake_account)
engine = create_engine(sf)
print(sf)
print(engine)
# alchemy_snow_connection = engine.connect()

snowflake_user = urllib.parse.quote_plus(snowflake_user)
snowflake_password = urllib.parse.quote_plus(snowflake_password)
sf = 'snowflake://{}:{}@{}'.format(snowflake_user, snowflake_password, snowflake_account)
engine = create_engine(sf)
print(sf)
print(engine)
alchemy_snow_connection = engine.connect()

Can someone please help me to fix this

Upvotes: 0

Views: 7360

Answers (2)

Srinath Menon
Srinath Menon

Reputation: 1642

The issue here is that you are most likely passing the user coming from Okta to be authenticated as an internal user. To ensure that the user credentials are validated from Okta itself, pass the following parameter in the code:

 authenticator=https://<okta_account_name>.okta.com

Upvotes: 1

Gord Thompson
Gord Thompson

Reputation: 123409

Use sqlalchemy.engine.URL to build your connection URL. It will take care of all the escaping for you.

from sqlalchemy import create_engine
from sqlalchemy.engine import URL

connection_url = URL.create(
    "snowflake",
    username=snowflake_user,
    password=snowflake_password,
    host=snowflake_account,
)
engine = create_engine(connection_url)

Upvotes: 1

Related Questions