-
Notifications
You must be signed in to change notification settings - Fork 526
Description
Python version
3.12
Operating system and processor architecture
AWS Lambda Runtime
Installed packages
snowflake-connector-python==4.1.0What did you do?
[ERROR] 2025-11-22T03:12:37.106Z 10b0363f-6f1b-4b74-a2af-338598ae5c63 An exception was raised in <bound method SnowflakeStorageClient.prepare_upload of <snowflake.connector.s3_storage_client.SnowflakeS3RestClient object at 0xffff1776a030>>
Traceback (most recent call last):
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/session_manager.py", line 198, in get_session
session = self._idle_sessions.pop()
^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: pop from empty list
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/file_transfer_agent.py", line 628, in function_and_callback_wrapper
work(*args, **kwargs),
^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/storage_client.py", line 228, in prepare_upload
self.preprocess()
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/storage_client.py", line 194, in preprocess
file_header = self.get_file_header(
^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/s3_storage_client.py", line 410, in get_file_header
response = self._send_request_with_authentication_and_retry(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/s3_storage_client.py", line 391, in _send_request_with_authentication_and_retry
return self._send_request_with_retry(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/storage_client.py", line 292, in _send_request_with_retry
with conn.rest.use_session(url=url) as session:
File "/var/lang/lib/python3.12/contextlib.py", line 137, in __enter__
return next(self.gen)
^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/session_manager.py", line 55, in wrapper
yield from generator_func(self, *args, **kwargs)
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/session_manager.py", line 502, in use_session
yield from self._yield_session_from_pool(url)
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/session_manager.py", line 509, in _yield_session_from_pool
session = pool.get_session(url=url)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/session_manager.py", line 200, in get_session
session = self._manager.make_session(url=url)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/session_manager.py", line 621, in make_session
if requests.utils.should_bypass_proxies(url, no_proxy=self.config.no_proxy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/vendored/requests/utils.py", line 783, in should_bypass_proxies
if is_ipv4_address(parsed.hostname):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lang/lib/python3.12/site-packages/snowflake/connector/vendored/requests/utils.py", line 703, in is_ipv4_address
socket.inet_aton(string_ip)
TypeError: inet_aton() argument 1 must be str, not bytesWhat did you expect to see?
Apologies, I have not yet had time to produce a MRE, however, I think I have identified the issue and potential fixes. I can produce an MRE if required, however, the relevant logs are above, and I will provide a summary now.
This caused some of our jobs at work to fail over the weekend (although I'm posting this from my personal account because of our security restrictions). Hopefully this is enough to work on a fix, or to act as a starting point / something to find via Google for other clients that hit this error in the new connector.
The Issue
When calling pandas_utils.write_pandas() in version 4.1.0 of the connector, with a connection object which uses a proxy, and in an AWS environment where we expect to upload the dataframe contents to S3, a TypeError is raised, as below (see logs and error).
TypeError: inet_aton() argument 1 must be str, not bytes
(See previous section for full traceback).
Reverting to version 4.0.0 of the connector resolves this issue, and it appears to be due to changes introduced in 9c9be36.
Cause
9c9be36 includes a change to how users can pass no_proxy values to a SessionManager object, which appears to be responsible for managing the underlying HTTP sessions used by requests.
There are also changes to the way the SessionManager object is instantiated, switching it to a factory pattern. The new pattern requires a URL to be passed when a new object is created, so that the URL itself can be checked against proxy logic, and so that the URL's hostname can be used as a key to manage a pool of sessions connected to different hosts.
Because these URLs can include cryptographic tokens, such as when they are used to connect to S3 during file uploads as part of the storage client logic, as happens in some of the pandas helper/integration functions, they can be either strings, or bytes.
However, when parsing the logic to do with proxies, they need to be inspected as strings, so that functions like is_ipv4_address() in the (vendored) requests library can inspect them to perform their logic (in this case, delegated to socket.inet_aton() which expects a string, which it converts into 32 bits to form the address).
However 9c9be36 refactors SessionManager.get_session() to now take a parameter url (for the reasons discussed above). The type of this parameter is annotated as str | None , but is being called with bytes by the S3 transport client.
It appears that there may be some uncertainty over whether the URL is bytes or string elsewhere in the SessionManager logic, too, such as in use_session(), which has a parameter url: str | bytes that is passed unmodified to make_session(self, *, url: str | None = None).