steam icon indicating copy to clipboard operation
steam copied to clipboard

[BUG] Timeout when requesting get_product_info

Open denizkoekden opened this issue 1 year ago • 13 comments

Description When I try "client.get_product_info(apps=[app_id], timeout=1)" I get an timeout. Of course before I initialize and login the Client and login anonymously with

client = SteamClient()
client.anonymous_login()

then I print(client) I get: <SteamClient(('155.133.226.75', 27028)) offline> So it seems like the SteamClient is offline?

Steps to Reproduce the behavior Run: app_id = 570 client = SteamClient() client.anonymous_login() info = client.get_product_info(apps=[app_id], timeout=1) print (info)

Expected behavior I expect informations about the provided App ID but since tonight I only get an timeout back Screenshots image Versions Report

python -m steam.versions_report
steam: 1.4.4

Dependencies:
                 vdf: 3.4
            protobuf: 3.20.3
            requests: 2.31.0
          cachetools: 5.3.2
              gevent: 24.10.2
 gevent-eventemitter: 2.1
       pycryptodomex: 3.21.0
              enum34: Not Installed
       win-inet-pton: Not Installed

Python runtime:
          executable: C:\Python312\python.exe
             version: 3.12.1 (tags/v3.12.1:2305ca5, Dec  7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)]
            platform: win32

System info:
              system: Windows
             machine: AMD64
             release: 11
             version: 10.0.22631```
</details>

denizkoekden avatar Oct 11 '24 15:10 denizkoekden

Hello, I have a similar problem, can't auth in steam using client.cli_login() or client.cli_login(). I add print(eresult) after self._pre_login() in "client/init.py/def login" and pre_login always returns EResult.TryAnotherCM. Why, I don't know

Sericck avatar Oct 11 '24 22:10 Sericck

Fighting with the same issue and while it doesn't seem easy to troubleshoot why the TCP connection is dropped, I've had better success with the websocket implementation suggested on PR #469 - not as perfect as some servers don't seem to communicate correctly for some reason..

https://gist.github.com/revij/da3a8ae03de673caf68ec1cfe79b5654

revij avatar Oct 12 '24 00:10 revij

Fighting with the same issue and while it doesn't seem easy to troubleshoot why the TCP connection is dropped, I've had better success with the websocket implementation suggested on PR #469 - not as perfect as some servers don't seem to communicate correctly for some reason..

https://gist.github.com/revij/da3a8ae03de673caf68ec1cfe79b5654

I use the login() function in CMClient.PROTOCOL_WEBSOCKET way, and your code is still problematic, but using anonymous_login() is normal

BlankTMing avatar Oct 12 '24 05:10 BlankTMing

Okay

Fighting with the same issue and while it doesn't seem easy to troubleshoot why the TCP connection is dropped, I've had better success with the websocket implementation suggested on PR #469 - not as perfect as some servers don't seem to communicate correctly for some reason..

https://gist.github.com/revij/da3a8ae03de673caf68ec1cfe79b5654

This is actually working in my test enviroment. I uninstalled the steam library (pip remove steam), then I installed the steam library from the PR (pip install https://github.com/njbooher/steam/archive/wsproto.zip) and then I added the following to the Code:

Import the following: from steam.core.connection import WebsocketConnection

Then add:

client.connection = WebsocketConnection()

after

client = SteamClient()

and then its working.

denizkoekden avatar Oct 12 '24 10:10 denizkoekden

get_product_info(apps=[app_id], timeout=1)

Trying to get multiple apps with get_product_info will have problems

BlankTMing avatar Oct 12 '24 11:10 BlankTMing

Okay

Fighting with the same issue and while it doesn't seem easy to troubleshoot why the TCP connection is dropped, I've had better success with the websocket implementation suggested on PR #469 - not as perfect as some servers don't seem to communicate correctly for some reason.. https://gist.github.com/revij/da3a8ae03de673caf68ec1cfe79b5654

This is actually working in my test enviroment. I uninstalled the steam library (pip remove steam), then I installed the steam library from the PR (pip install https://github.com/njbooher/steam/archive/wsproto.zip) and then I added the following to the Code:

Import the following: from steam.core.connection import WebsocketConnection

Then add:

client.connection = WebsocketConnection()

after

client = SteamClient()

and then its working.

While it seems to work with some websocket servers, I had trouble with the ones located in fra1/fra2/ams/vie1 but the ones in par1/sto1/sto2/waw1 work just fine. Connections to the "broken" sites also reach to the "ClientPICSProductInfoRequest" point but then seem to receive a "Try another CM" response as well.

revij avatar Oct 12 '24 11:10 revij

Okay. I just tried it from multiple Servers I run in germany and they all can connect to Steam Servers reliable.

<SteamClient(('cmp1-fra1.steamserver.net', 27019)) online>

denizkoekden avatar Oct 12 '24 11:10 denizkoekden

OK, I fixed it, he still uses TCP

def bootstrap_from_webapi(self, cell_id=0):
       
        from steam import webapi
        try:
            resp = webapi.get('ISteamDirectory', 'GetCMListForConnect', 1, params={'cmtype': 'netfilter',
                                                                         'http_timeout': 3})
        except Exception as exp:
            self._LOG.error("WebAPI boostrap failed: %s" % str(exp))
            return False

        result = EResult(resp['response']['success'])

        if result != EResult.OK:
            self._LOG.error("GetCMList failed with %s" % repr(result))
            return False

        serverlist = resp['response']['serverlist']
        self._LOG.debug("Received %d servers from WebAPI" % len(serverlist))

        def str_to_tuple(serveraddr):
            ip, port = serveraddr['endpoint'].split(':')
            return str(ip), int(port)

        self.clear()
        self.cell_id = cell_id
        self.merge_list(map(str_to_tuple, serverlist))

        return True

BlankTMing avatar Oct 13 '24 06:10 BlankTMing

Alright, I had a feeling the implementation from the PR wasn’t perfect as it might be a first draft, but it’s still an improvement over the previous state where nothing worked at all. Can we gather the issues we’ve found and revise the PR? I also noticed that @revij made a few adjustments in his fork. Overall, improving this would benefit many Steam projects. If I find the time them I’ll dive deeper into the code and the topic next week to see what’s still missing and not working.

denizkoekden avatar Oct 13 '24 08:10 denizkoekden

Plus one here:

client.anonymous_login()
<EResult.TryAnotherCM: 48>

And:

info: dict = client.get_product_info(apps=[258550], timeout=1)
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevconsole.py", line 364, in runcode
    coro = func()
           ^^^^^^
  File "<input>", line 1, in <module>
  File "/Users/maxpfeiffer/repos/rust-game-server-docker/.venv/lib/python3.11/site-packages/steam/client/builtins/apps.py", line 139, in get_product_info
    chunk = self.wait_event(job_id, timeout=timeout, raises=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/maxpfeiffer/repos/rust-game-server-docker/.venv/lib/python3.11/site-packages/eventemitter/__init__.py", line 119, in wait_event
    return result.get(True, timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "src/gevent/event.py", line 329, in gevent._gevent_cevent.AsyncResult.get
  File "src/gevent/event.py", line 356, in gevent._gevent_cevent.AsyncResult.get
  File "src/gevent/_abstract_linkable.py", line 487, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
  File "src/gevent/_abstract_linkable.py", line 490, in gevent._gevent_c_abstract_linkable.AbstractLinkable._wait_core
  File "src/gevent/_abstract_linkable.py", line 442, in gevent._gevent_c_abstract_linkable.AbstractLinkable._AbstractLinkable__wait_to_be_notified
  File "src/gevent/_abstract_linkable.py", line 451, in gevent._gevent_c_abstract_linkable.AbstractLinkable._switch_to_hub
  File "src/gevent/_greenlet_primitives.py", line 61, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_greenlet_primitives.py", line 65, in gevent._gevent_c_greenlet_primitives.SwitchOutGreenletWithLoop.switch
  File "src/gevent/_gevent_c_greenlet_primitives.pxd", line 35, in gevent._gevent_c_greenlet_primitives._greenlet_switch
gevent.timeout.Timeout: 1 second

max-pfeiffer avatar Oct 16 '24 18:10 max-pfeiffer

OK, I fixed it, he still uses TCP

def bootstrap_from_webapi(self, cell_id=0):
       
        from steam import webapi
        try:
            resp = webapi.get('ISteamDirectory', 'GetCMListForConnect', 1, params={'cmtype': 'netfilter',
                                                                         'http_timeout': 3})
        except Exception as exp:
            self._LOG.error("WebAPI boostrap failed: %s" % str(exp))
            return False

        result = EResult(resp['response']['success'])

        if result != EResult.OK:
            self._LOG.error("GetCMList failed with %s" % repr(result))
            return False

        serverlist = resp['response']['serverlist']
        self._LOG.debug("Received %d servers from WebAPI" % len(serverlist))

        def str_to_tuple(serveraddr):
            ip, port = serveraddr['endpoint'].split(':')
            return str(ip), int(port)

        self.clear()
        self.cell_id = cell_id
        self.merge_list(map(str_to_tuple, serverlist))

        return True

This is working well for me. No observed errors using this approach instead of the websocket method.

MABBTT avatar Oct 16 '24 19:10 MABBTT

I switched to detiam's fork, where he implemented the fix: https://github.com/detiam/steam_websocket

My Poetry config:

steam = {git = "https://github.com/detiam/steam_websocket.git", branch = "master", extras=["client"]}

@detiam Thanks a lot for fixing the issue!

max-pfeiffer avatar Oct 20 '24 12:10 max-pfeiffer

It seems that the issue on Steam's side has been resolved, as the code that stopped working few weeks ago is now functioning again 🤔

kurokobo avatar Oct 23 '24 15:10 kurokobo