@@ -94,6 +94,46 @@ You can optionally specify the initial database and schema for the Snowflake ses
94
94
' snowflake://<user_login_name>:<password>@<account_name>/<database_name>/<schema_name>?warehouse=<warehouse_name>&role=<role_name>'
95
95
```
96
96
97
+ # ### Escaping Special Characters such as `%, @` signs in Passwords
98
+
99
+ As pointed out in [SQLAlchemy](https:// docs.sqlalchemy.org/ en/ 14 / core/ engines.html# escaping-special-characters-such-as-signs-in-passwords), URLs
100
+ containing special characters need to be URL encoded to be parsed correctly. This includes the `% , @ ` signs. Unescaped password containing special
101
+ characters could lead to authentication failure.
102
+
103
+ The encoding for the password can be generated using `urllib.parse` :
104
+ ```python
105
+ import urllib.parse
106
+ urllib.parse.quote(" kx@% jj5/g" )
107
+ ' kx%40% 25%20jj5/g'
108
+ ```
109
+
110
+ ** Note** : `urllib.parse.quote_plus` may also be used if there is no space in the string, as `urllib.parse.quote_plus` will replace space with `+ ` .
111
+
112
+ To create an engine with the proper encodings, either manually constructing the url string by formatting
113
+ or taking advantage of the `snowflake.sqlalchemy.URL ` helper method:
114
+ ```python
115
+ import urllib.parse
116
+ from snowflake.sqlalchemy import URL
117
+ from sqlalchemy import create_engine
118
+
119
+ quoted_password = urllib.parse.quote(" kx@% jj5/g" )
120
+
121
+ # 1. manually constructing an url string
122
+ url = f ' snowflake://testuser1: { quoted_password} @abc123/testdb/public?warehouse=testwh&role=myrole '
123
+ engine = create_engine(url)
124
+
125
+ # 2. using the snowflake.sqlalchemy.URL helper method
126
+ engine = create_engine(URL(
127
+ account = ' abc123' ,
128
+ user = ' testuser1' ,
129
+ password = quoted_password,
130
+ database = ' testdb' ,
131
+ schema = ' public' ,
132
+ warehouse = ' testwh' ,
133
+ role = ' myrole' ,
134
+ ))
135
+ ```
136
+
97
137
** Note** :
98
138
After login, the initial database, schema, warehouse and role specified in the connection string can always be changed for the session.
99
139
0 commit comments