snowflake python connector throws 403 forbidden after 6 hours

Viewed 1144

I have a piece of code that downloads large amounts of data(>200M) from snowflake and writes it into my local database. I am using Python Snowflake connector v2.1.3 to pull my data. It runs properly for ~6 hours after which it starts to throw 403 error from snowflake and eventually shuts down. I have tried using the recommended params such as "insecure_mode=True" and "client_session_keep_alive=True", but nothing work

2021-05-12 09:45:40,061 [INFO/ForkPoolWorker-2/pid(26)][/app/.venv/lib/python3.7/site-packages/snowflake/connector/ssl_wrap_socket.py:427] THIS CONNECTION IS IN INSECURE MODE. IT MEANS THE CERTIFICATE WILL BE VALIDATED BUT THE CERTIFICATE REVOCATION STATUS WILL NOT BE CHECKED.
2021-05-12 09:45:40,279 [DEBUG/ForkPoolWorker-2/pid(26)][/app/.venv/lib/python3.7/site-packages/urllib3/connectionpool.py:393] https://sfc-va-ds1-2-customer-stage.s3.amazonaws.com:443 "GET /9jz1-s-vass3666/results/019c2ffa-0502-21c7-0000-39b10525bbee_0/main/data_0_0_18?x-amz-server-side-encryption-customer-algorithm=AES256&response-content-encoding=gzip&AWSAccessKeyId=<key_id>&Expires=1620808614&Signature=<signature> HTTP/1.1" 403 None
2021-05-12 09:45:40,280 [DEBUG/ForkPoolWorker-2/pid(26)][/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py:822] HTTP 403: Forbidden. Retrying...
2021-05-12 09:45:40,281 [ERROR/ForkPoolWorker-2/pid(26)][/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py:678] HTTP 403: Forbidden
Traceback (most recent call last):
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py", line 652, in _request_exec_wrapper
    **kwargs)
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py", line 913, in _request_exec
    raise err
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py", line 824, in _request_exec
    raise RetryRequest(exi)
snowflake.connector.network.RetryRequest: HTTP 403: Forbidden
2021-05-12 09:45:40,282 [DEBUG/ForkPoolWorker-2/pid(26)][/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py:953] Active requests sessions: 1, idle: 3
2021-05-12 09:45:40,282 [ERROR/ForkPoolWorker-2/pid(26)][/app/.venv/lib/python3.7/site-packages/snowflake/connector/chunk_downloader.py:148] Failed to fetch the large result set chunk 18/2035
Traceback (most recent call last):
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py", line 652, in _request_exec_wrapper
    **kwargs)
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py", line 913, in _request_exec
    raise err
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py", line 824, in _request_exec
    raise RetryRequest(exi)
snowflake.connector.network.RetryRequest: HTTP 403: Forbidden

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/chunk_downloader.py", line 125, in _download_chunk
    result_data = self._fetch_chunk(self._chunks[idx].url, headers)
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/chunk_downloader.py", line 258, in _fetch_chunk
    binary_data_handler=handler)
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py", line 612, in fetch
    **kwargs)
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py", line 692, in _request_exec_wrapper
    Error.errorhandler_wrapper(conn, None, cause)
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/errors.py", line 100, in errorhandler_wrapper
    connection.errorhandler(connection, cursor, errorclass, errorvalue)
  File "/app/.venv/lib/python3.7/site-packages/snowflake/connector/errors.py", line 73, in default_errorhandler
    done_format_msg=errorvalue.get(u'done_format_msg'))
snowflake.connector.errors.ForbiddenError: HTTP 403: Forbidden

and all that you know after this is

2021-05-12 09:45:46,405 [DEBUG/ForkPoolWorker-2/pid(26)][/app/.venv/lib/python3.7/site-packages/urllib3/connectionpool.py:393] https://sfc-va-ds1-2-customer-stage.s3.amazonaws.com:443 "GET /9jz1-s-vass3666/results/019c2ffa-0502-21c7-0000-39b10525bbee_0/main/data_0_0_19?x-amz-server-side-encryption-customer-algorithm=AES256&response-content-encoding=gzip&AWSAccessKeyId=<key>&Expires=1620808614&Signature=<signature> HTTP/1.1" 403 None
2021-05-12 09:45:46,406 [DEBUG/ForkPoolWorker-2/pid(26)][/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py:822] HTTP 403: Forbidden. Retrying...
2021-05-12 09:45:46,407 [DEBUG/ForkPoolWorker-2/pid(26)][/app/.venv/lib/python3.7/site-packages/snowflake/connector/network.py:706] retrying: errorclass=<class 'snowflake.connector.errors.ForbiddenError'>, error=HTTP 403: Forbidden, counter=136, sleeping=16(s)

it looks to me that the connection to snowflake is active but the connection to the stage is expired, is there any way that I can solve this ?

0 Answers
Related