HuobiRDCenter / huobi_Python

Python SDK for Huobi Spot API
https://huobiapi.github.io/docs/spot/v1/en
Apache License 2.0
682 stars 333 forks source link

AttributeError: 'WebsocketManage' object has no attribute 're_connect_in_delay' #55

Closed shurmanov closed 3 years ago

shurmanov commented 4 years ago

I recently upgraded to v2.0.0,

Whenever the internet disappears and then the internet comes back again, this error is striking.

Job "watch_dog_job (trigger: interval[0:00:01], next run at: 2020-07-08 18:52:18 +05)" raised an exception
Traceback (most recent call last):
  File "...src/huobi-client/huobi/connection/impl/websocket_watchdog.py", line 27, in watch_dog_job
    websocket_manage.re_connect_in_delay(watch_dog_obj.reconnect_after_ms)
AttributeError: 'WebsocketManage' object has no attribute 're_connect_in_delay'

I guess it's pretty clear, on v2.0.0 re_connect_in_delay is not implemented or removed in WebsocketManage.

How can I hotfix this with at least monkey patching?

vipxlm commented 4 years ago

我也遇到了,这问题怎么解?

shurmanov commented 3 years ago

显然,这种方法没有实现。 我通过猴子补丁解决了这个问题,也就是说,我通过在运行时重写其类来更改了此方法。

def patch_watch_dog_job_function():
    from huobi.connection.impl.websocket_watchdog import ConnectionState, get_current_timestamp
    import huobi.connection.impl.websocket_watchdog

    @logger.catch
    def patched_watch_dog_job(*args):
        watch_dog_obj = args[0]

        for idx, websocket_manage in enumerate(watch_dog_obj.websocket_manage_list):
            if websocket_manage.request.auto_close == True:  # setting auto close no need reconnect
                pass
            elif websocket_manage.state == ConnectionState.CONNECTED:
                if watch_dog_obj.is_auto_connect:
                    ts = get_current_timestamp() - websocket_manage.last_receive_time
                    if ts > watch_dog_obj.heart_beat_limit_ms:
                        watch_dog_obj.logger.warning("[Sub][" + str(websocket_manage.id) + "] No response from server")
                        websocket_manage.close_and_wait_reconnect(watch_dog_obj.wait_reconnect_millisecond())
            elif websocket_manage.state == ConnectionState.WAIT_RECONNECT:
                watch_dog_obj.logger.warning("[Sub] call re_connect")
                websocket_manage.re_connect()
                pass
            elif websocket_manage.state == ConnectionState.CLOSED_ON_ERROR:
                logger.critical("Smth went wrong with network")
                logger.critical(str(websocket_manage))
                if watch_dog_obj.is_auto_connect:
                    websocket_manage.re_connect()
                    pass

    huobi.connection.impl.websocket_watchdog.watch_dog_job = patched_watch_dog_job

然后我在使用火币客户端之前在其他地方调用了此函数。

shuangbi commented 3 years ago

already fixed in latest release