Open
Description
I'm trying to use the anthropic-sdk on both Windows and macOS, but I'm encountering the following error on both platforms:
anthropic\_base_client.py:795 Message: AttributeError: module 'socket' has no attribute 'TCP_KEEPINTVL'
After investigating, I found that the socket.TCP_KEEPINTVL attribute isn't available on all platforms, particularly Windows and macOS.
To resolve the issue locally, I modified _base_client.py as follows:
if "transport" not in kwargs:
socket_options = [
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, True)
]
if getattr(socket, 'TCP_KEEPINTVL', None) is not None:
socket_options += [(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 60)]
elif sys.platform == 'darwin':
TCP_KEEPALIVE = getattr(socket, 'TCP_KEEPALIVE', 0x10)
socket_options += [(socket.IPPROTO_TCP, TCP_KEEPALIVE, 60)]
if getattr(socket, 'TCP_KEEPCNT', None) is not None:
socket_options += [(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 5)]
TCP_KEEPIDLE = getattr(socket, "TCP_KEEPIDLE", None)
if TCP_KEEPIDLE is not None:
socket_options.append((socket.IPPROTO_TCP, TCP_KEEPIDLE, 60))
With this change, the SDK works as expected on both platforms.
Would this be a valid fix to submit as a PR? Happy to open one if this approach looks good.
Metadata
Metadata
Assignees
Labels
No labels