我有一个非常基本的脚本,可以连接到snowflake python连接,但一旦我把它放在jupyter笔记本中,我得到下面的错误,真的不知道为什么?
import snowflake.connector
conn = snowflake.connector.connect(account='account',
user='user',
password='password',
database='db')
误差
OperationalError Traceback (most recent call last)
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/connection.py:1125, in SnowflakeConnection._authenticate(self, auth_instance)
1124 try:
-> 1125 auth.authenticate(
1126 auth_instance=auth_instance,
1127 account=self.account,
1128 user=self.user,
1129 database=self.database,
1130 schema=self.schema,
1131 warehouse=self.warehouse,
1132 role=self.role,
1133 passcode=self._passcode,
1134 passcode_in_password=self._passcode_in_password,
1135 mfa_callback=self._mfa_callback,
1136 password_callback=self._password_callback,
1137 session_parameters=self._session_parameters,
1138 )
1139 except OperationalError as e:
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/auth/_auth.py:250, in Auth.authenticate(self, auth_instance, account, user, database, schema, warehouse, role, passcode, passcode_in_password, mfa_callback, password_callback, session_parameters, timeout)
249 try:
--> 250 ret = self._rest._post_request(
251 url,
252 headers,
253 json.dumps(body),
254 timeout=auth_timeout,
255 socket_timeout=auth_timeout,
256 )
257 except ForbiddenError as err:
258 # HTTP 403
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/network.py:716, in SnowflakeRestful._post_request(self, url, headers, body, token, timeout, _no_results, no_retry, socket_timeout, _include_retry_params)
714 pprint(ret)
--> 716 ret = self.fetch(
717 "post",
718 full_url,
719 headers,
720 data=body,
721 timeout=timeout,
722 token=token,
723 no_retry=no_retry,
724 socket_timeout=socket_timeout,
725 _include_retry_params=_include_retry_params,
726 )
727 logger.debug(
728 "ret[code] = {code}, after post request".format(
729 code=(ret.get("code", "N/A"))
730 )
731 )
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/network.py:814, in SnowflakeRestful.fetch(self, method, full_url, headers, data, timeout, **kwargs)
813 while True:
--> 814 ret = self._request_exec_wrapper(
815 session, method, full_url, headers, data, retry_ctx, **kwargs
816 )
817 if ret is not None:
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/network.py:937, in SnowflakeRestful._request_exec_wrapper(self, session, method, full_url, headers, data, retry_ctx, no_retry, token, **kwargs)
936 if not no_retry:
--> 937 raise e
938 logger.debug("Ignored error", exc_info=True)
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/network.py:868, in SnowflakeRestful._request_exec_wrapper(self, session, method, full_url, headers, data, retry_ctx, no_retry, token, **kwargs)
867 return return_object
--> 868 self._handle_unknown_error(method, full_url, headers, data, conn)
869 TelemetryService.get_instance().log_http_request_error(
870 "HttpRequestUnknownError",
871 full_url,
(...)
876 retry_count=retry_ctx.cnt,
877 )
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/network.py:992, in SnowflakeRestful._handle_unknown_error(self, method, full_url, headers, data, conn)
987 logger.error(
988 f"Failed to get the response. Hanging? "
989 f"method: {method}, url: {full_url}, headers:{headers}, "
990 f"data: {data}"
991 )
--> 992 Error.errorhandler_wrapper(
993 conn,
994 None,
995 OperationalError,
996 {
997 "msg": f"Failed to get the response. Hanging? method: {method}, url: {full_url}",
998 "errno": ER_FAILED_TO_REQUEST,
999 },
1000 )
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/errors.py:290, in Error.errorhandler_wrapper(connection, cursor, error_class, error_value)
274 """Error handler wrapper that calls the errorhandler method.
275
276 Args:
(...)
287 exception to the first handler in that order.
288 """
--> 290 handed_over = Error.hand_to_other_handler(
291 connection,
292 cursor,
293 error_class,
294 error_value,
295 )
296 if not handed_over:
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/errors.py:348, in Error.hand_to_other_handler(connection, cursor, error_class, error_value)
347 elif connection is not None:
--> 348 connection.errorhandler(connection, cursor, error_class, error_value)
349 return True
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/errors.py:221, in Error.default_errorhandler(connection, cursor, error_class, error_value)
220 done_format_msg = error_value.get("done_format_msg")
--> 221 raise error_class(
222 msg=error_value.get("msg"),
223 errno=None if errno is None else int(errno),
224 sqlstate=error_value.get("sqlstate"),
225 sfqid=error_value.get("sfqid"),
226 query=error_value.get("query"),
227 done_format_msg=(
228 None if done_format_msg is None else bool(done_format_msg)
229 ),
230 connection=connection,
231 cursor=cursor,
232 )
OperationalError: 250003: Failed to get the response. Hanging? method: post, url: https://xw81982.us-east4.gcp.snowflakecomputing.com.snowflakecomputing.com:443/session/v1/login-request?request_id=cedc0862-8df4-4cb1-a617-5216d2a16254&databaseName=Product&request_guid=435b4fa9-7df9-494c-b0b1-5238c26c032e
The above exception was the direct cause of the following exception:
OperationalError Traceback (most recent call last)
Cell In[6], line 2
1 import snowflake.connector
----> 2 conn = snowflake.connector.connect(account='xw81982.us-east4.gcp.snowflakecomputing.com',
3 user='03pes03',
4 password='Copper333,,',
5 database='Product')
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/__init__.py:51, in Connect(**kwargs)
50 def Connect(**kwargs) -> SnowflakeConnection:
---> 51 return SnowflakeConnection(**kwargs)
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/connection.py:304, in SnowflakeConnection.__init__(self, **kwargs)
302 self.converter = None
303 self.__set_error_attributes()
--> 304 self.connect(**kwargs)
305 self._telemetry = TelemetryClient(self._rest)
307 # get the imported modules from sys.modules
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/connection.py:571, in SnowflakeConnection.connect(self, **kwargs)
569 connection_diag.generate_report()
570 else:
--> 571 self.__open_connection()
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/connection.py:839, in SnowflakeConnection.__open_connection(self)
835 else:
836 # okta URL, e.g., https://<account>.okta.com/
837 self.auth_class = AuthByOkta(application=self.application)
--> 839 self.authenticate_with_retry(self.auth_class)
841 self._password = None # ensure password won't persist
842 self.auth_class.reset_secrets()
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/connection.py:1099, in SnowflakeConnection.authenticate_with_retry(self, auth_instance)
1096 def authenticate_with_retry(self, auth_instance) -> None:
1097 # make some changes if needed before real __authenticate
1098 try:
-> 1099 self._authenticate(auth_instance)
1100 except ReauthenticationRequest as ex:
1101 # cached id_token expiration error, we have cleaned id_token and try to authenticate again
1102 logger.debug("ID token expired. Reauthenticating...: %s", ex)
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/connection.py:1170, in SnowflakeConnection._authenticate(self, auth_instance)
1168 except OperationalError as auth_op:
1169 if auth_op.errno == ER_FAILED_TO_CONNECT_TO_DB:
-> 1170 raise auth_op from e
1171 logger.debug("Continuing authenticator specific timeout handling")
1172 continue
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/connection.py:1147, in SnowflakeConnection._authenticate(self, auth_instance)
1145 while True:
1146 try:
-> 1147 auth_instance.handle_timeout(
1148 authenticator=self._authenticator,
1149 service_name=self.service_name,
1150 account=self.account,
1151 user=self.user,
1152 password=self._password,
1153 )
1154 auth.authenticate(
1155 auth_instance=auth_instance,
1156 account=self.account,
(...)
1166 session_parameters=self._session_parameters,
1167 )
1168 except OperationalError as auth_op:
File ~/Library/Python/3.8/lib/python/site-packages/snowflake/connector/auth/by_plugin.py:214, in AuthByPlugin.handle_timeout(***failed resolving arguments***)
212 if not self._retry_ctx.should_retry():
213 self._retry_ctx.reset()
--> 214 raise OperationalError(
215 msg=f"Could not connect to Snowflake backend after {self._retry_ctx.get_current_retry_count()} attempt(s)."
216 "Aborting",
217 errno=ER_FAILED_TO_CONNECT_TO_DB,
218 )
219 else:
220 logger.debug(
221 f"Hit connection timeout, attempt number {self._retry_ctx.get_current_retry_count()}."
222 " Will retry in a bit..."
223 )
OperationalError: 250001: Could not connect to Snowflake backend after 0 attempt(s).Aborting
尝试0次后端连接失败
假说:
提供的账号不正确-包含完整的url
如果url为
https://xxxxx.region.cloud_provider.snowflakecomputing.com
则账户不应包含.snowflakecomputing.com
import snowflake.connector
conn = snowflake.connector.connect(account='xxxxx.region.cloud_provider',
user='user',
password='password',
database='db')
还建议在连接设置过程中显式列出role/warehouse
,否则将使用用户的默认值。