KristiLuna
KristiLuna

Reputation: 1903

Snowflake Account must be specified error, but it is specified

I have the below code, I have the account, username, pw, etc, but I'm still seeing the below error:

raise error_class( sqlalchemy.exc.ProgrammingError: (snowflake.connector.errors.ProgrammingError) 251001: Account must be specified

I've also tried by changing the engine variable in my created_db_engine function like below, but I see the same error:

engine = snowflake.connector.connect(
                user='USER',
                password='PASSWORD',
                account='ACCOUNT',
                warehouse='WAREHOUSE',
                database='DATABASE',
                schema='SCHEMA'
                )

here is my code

import pandas as pd
from snowflake.sqlalchemy import URL
from sqlalchemy import create_engine
import snowflake.connector
from snowflake.connector.pandas_tools import write_pandas, pd_writer
from pandas import json_normalize
import requests

  
df = 'my_dataframe'

   
def create_db_engine(db_name, schema_name):
    engine = URL(
        account="ab12345.us-west-2.snowflakecomputing.com",
        user="my_user",
        password="my_pw",
        database="DB",
        schema="PUBLIC",
        warehouse="WH1",
        role="DEV"
    )
    return engine


def create_table(out_df, table_name, idx=False):
    url = create_db_engine(db_name="db", schema_name="skm")
    engine = create_engine(url)
    connection = engine.connect()

    try:
        out_df.to_sql(
            table_name, connection, if_exists="append", index=idx, method=pd_writer
        )

    except ConnectionError:
        print("Unable to connect to database!")

    finally:
        connection.close()
        engine.dispose()

    return True

print(df.head)

create_table(df, "reporting")

Upvotes: 3

Views: 5354

Answers (1)

CMe
CMe

Reputation: 692

Given the Snowflake documentation for SqlAlchemy, your account parameter should not include snowflakecomputing.com.

So you should try with ab12345.us-west-2 and connector will append the domain part automatically for you.

Upvotes: 9

Related Questions