Skip to content

Bug: binance-sdk-spot returns "UserDataStreamSubscribeSignatureResponse' object has no attribute 'get'" #523

@nikita-doronin

Description

@nikita-doronin

Packeges:

binance-sdk-spot==8.2.0
binance-common==3.8.0
Python: 3.14

Bug description:

At binance-sdk-spot the both methods user_data_stream_subscribe_signature() and user_data_stream_subscribe() in websocket_api.py crash with AttributeError because they call .get() on a Pydantic BaseModel object, which does not have a .get() method:

# binance_sdk_spot/websocket_api/websocket_api.py
response = await self._userDataStreamApi.user_data_stream_subscribe_signature(
    id, recv_window
)
data = response.data()
if data.get("result") is None or data.get("error") is not None:  # <-- BUG
    raise ValueError(data)

response.data() returns a UserDataStreamSubscribeSignatureResponse instance, which is a Pydantic BaseModel (defined in websocket_api/models/user_data_stream_subscribe_signature_response.py). Pydantic models do not have a .get() method - that is a dict method. The same bug exists for the non-signature variant user_data_stream_subscribe().

Suggested fix:

# if data.get("result") is None or data.get("error") is not None: # <-- delete this 

if data.result is None or getattr(data, "error", None) is not None: # <-- add this

The identical fix applies to both line 3036 user_data_stream_subscribe() and line 3075 user_data_stream_subscribe_signature().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions