# How to connect to Snowflake using info from snowflake\_connector\_python

**URL:** https://discourse.greatexpectations.io/t/how-to-connect-to-snowflake-using-info-from-snowflake-connector-python/1550
**Category:** GX Core Support
**Tags:** how-to, help-wanted
**Created:** [January 3, 2024, 8:36pm UTC](https://discourse.greatexpectations.io/t/how-to-connect-to-snowflake-using-info-from-snowflake-connector-python/1550 "2024-01-03T20:36:24Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dnikolic](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@dnikolic](https://discourse.greatexpectations.io/u/dnikolic)
#### Post date: [January 3, 2024, 8:36pm UTC](https://discourse.greatexpectations.io/t/how-to-connect-to-snowflake-using-info-from-snowflake-connector-python/1550/1 "2024-01-03T20:36:24Z")

</div>

I use following code to connect to Snowflake from python (using snowflake\_connector\_python version 3.0.1).

```auto
import snowflake.connector

snowflake.connector.connect(
            authenticator='externalbrowser',
            user=user,
            role=role,
            warehouse=warehouse,
            account=account,
            region=region)

```

Please note that my authenticator is ‘externalbrowser’. I’m using browser based SSO.

My question is how should I connect from GX? What should be my connection string and how do I provide ‘authenticator’ parameter?

I appreciate help, thanks a lot 🙂

---

<div class="post-metadata">

### Author: ![rachel.house](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/rachel.house/32/236_2.png) [@rachel.house](https://discourse.greatexpectations.io/u/rachel.house)
#### Post date: [January 4, 2024, 4:12pm UTC](https://discourse.greatexpectations.io/t/how-to-connect-to-snowflake-using-info-from-snowflake-connector-python/1550/2 "2024-01-04T16:12:43Z")

</div>

Hi @dnikolic, thanks for reaching out!

First, here’s a link to our docs page on connecting to Snowflake data if you haven’t yet seen it: [Connect to SQL database Data Assets](https://docs.greatexpectations.io/docs/oss/guides/connecting_to_your_data/fluent/database/connect_sql_source_data)

For browser-based SSO authentication, the connection string format that you want to use is below; note that you’ll have the additional query param `authenticator=externalbrowser` and you need to set your password to an empty string.

```python
snowflake://{USER_NAME}:{PASSWORD}@{ACCOUNT_NAME}/{DATABASE_NAME}/{SCHEMA_NAME}?warehouse={WAREHOUSE_NAME}&role={ROLE_NAME}&authenticator=externalbrowser

```

Here’s an example of creating a Snowflake Data Source with that connection string:

```python
import os
import great_expectations as gx

USER_NAME = os.getenv("SNOWFLAKE_USERNAME")
ACCOUNT_NAME = os.getenv("SNOWFLAKE_ACCOUNT")
PASSWORD = ""

ROLE_NAME = "<your-role>"
DATABASE_NAME = "<your-database>"
SCHEMA_NAME = "<your-schema>"
WAREHOUSE_NAME = "<your-warehouse>"

snowflake_connection_str = (
    f"snowflake://{USER_NAME}:{PASSWORD}@{ACCOUNT_NAME}/{DATABASE_NAME}/{SCHEMA_NAME}?"
    f"warehouse={WAREHOUSE_NAME}&role={ROLE_NAME}&authenticator=externalbrowser"
)

context = gx.get_context()

datasource = context.sources.add_snowflake(
    name="snowflake_data_source",
    connection_string=snowflake_connection_str
)

```

---

<div class="post-metadata">

### Author: ![dnikolic](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@dnikolic](https://discourse.greatexpectations.io/u/dnikolic)
#### Post date: [January 8, 2024, 11:44am UTC](https://discourse.greatexpectations.io/t/how-to-connect-to-snowflake-using-info-from-snowflake-connector-python/1550/3 "2024-01-08T11:44:53Z")

</div>

Hi @rachel.house , thanks a lot for prompt response.

It is now clear how to provide ‘authenticator’ parameter, thanks.

Unfortunaltely I’m still not able to connect. Getting following error:

```auto
raise TestConnectionError(
great_expectations.datasource.fluent.interfaces.TestConnectionError: Attempt to connect to datasource failed with the following error message: 
(snowflake.connector.errors.OperationalError) 250003: Failed to get the response. Hanging? method: post, 
url: https://myaccount.snowflakecomputing.com:443/session/authenticator-request?request_guid=2df584de-b8d1-4e8b-9087-d1a5ed6ea5c1

```

I noticed that in my python connection string (which works fine) I have also ‘region’ parameter. I tried using following connection string:

```auto
f"snowflake://{USER_NAME}:{PASSWORD}@{ACCOUNT_NAME}/{REGION}/{DATABASE_NAME}/{SCHEMA_NAME}?"
    f"warehouse={WAREHOUSE_NAME}&role={ROLE_NAME}&authenticator=externalbrowser"

```

but that did not work. Error was ‘Invalid name space is specified: /\<database\_name\>/\<schema\_name\>’.

Any suggestion?

Thanks a lot 🙂

---

<div class="post-metadata">

### Author: ![rachel.house](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/rachel.house/32/236_2.png) [@rachel.house](https://discourse.greatexpectations.io/u/rachel.house)
#### Post date: [January 8, 2024, 3:28pm UTC](https://discourse.greatexpectations.io/t/how-to-connect-to-snowflake-using-info-from-snowflake-connector-python/1550/4 "2024-01-08T15:28:34Z")

</div>

Hi @dnikolic, the authenticator query param is the `&authenticator=externalbrowser` text at the end of the connection string - it’s provided just by including it in the connection string (as shown in my last message).

You don’t need to include region separately. I see now that calling it `ACCOUNT_NAME` in my example might have been confusing, since [Snowflake has two formats of account identifiers, the **account name** and the **account locator**](https://docs.snowflake.com/en/user-guide/admin-account-identifier). You can use either the account name or account locator in the connection string.

- Note that if you [copy your account name using the Snowflake instructions](https://docs.snowflake.com/en/user-guide/admin-account-identifier#finding-the-organization-and-account-name-for-an-account), it’ll be in format `<orgname>.<account_name>`. For the connection string, replace the period (`.`) with a hyphen (`-`). An example copied account name `WGECESQ.WBU94726` would be specified as `WGECESQ-WBU94726` in your connection string.

As an example, below are two connection strings, with fake values, that use the correct connection string format:

```bash
snowflake://{USER_NAME}:{PASSWORD}@{ACCOUNT_IDENTIFIER}/{DATABASE_NAME}/{SCHEMA_NAME}?warehouse={WAREHOUSE_NAME}&role={ROLE_NAME}&authenticator=externalbrowser

```

With **account name** :

```bash
snowflake://snowflakeuser1:@WGECESQ-WBU94726/SNOWFLAKEDB/MYTABLE?warehouse=DEFAULT_WAREHOUSE&role=PUBLIC&authenticator=externalbrowser

```

With **account locator** :

```bash
snowflake://snowflakeuser1:@wbu94726.us-east-1/SNOWFLAKEDB/MYTABLE?warehouse=DEFAULT_WAREHOUSE&role=PUBLIC&authenticator=externalbrowser

```
