ValvePython / steam

☁️ Python package for interacting with Steam
http://steam.readthedocs.io
MIT License
1.11k stars 148 forks source link

Client random reconnects causing issues with get_product_info() #281

Closed vBubbaa closed 4 years ago

vBubbaa commented 4 years ago

I have a website running Steamkit to monitor Steam (very similar to steamdb.info), and recently I have ran into a bug with Steamkit that I cannot figure out.

I have a few script I use to get this to work, a script that check for steam changes every few seconds and creates a task in a build in basic tasking system I have created. I have a script that processes these changes and uses client get_product_info() to fetch the information. I have recently ran into a problem where Steamkit seemingly randomly disconnects and then reconnects and after the steam client reconnects, the get_product_info() response is returning empty. I'm not entirely sure if this issue is on my end, or steamkits or maybe I configured the steam client incorrectly.

Any help would be appreciated.

Here is my Client I have setup that is almost identical to the recipe client example for WebAPI:

from steam.client import SteamClient
from steam.core.msg import MsgProto
from steam.enums.emsg import EMsg
from steam.utils.proto import proto_to_dict
import logging
import gevent
from binascii import hexlify
import logging
import vdf

class SteamWorker(object):
    def __init__(self):
        self.steam = client = SteamClient()
        self.logged_on_once = False

        @client.on("error")
        def handle_error(result):
            print("Logon result: %s", repr(result))

        @client.on("connected")
        def handle_connected():
            print("Connected to %s", client.current_server_addr)

        @client.on("logged_on")
        def handle_after_logon():
            self.logged_on_once = True

            print("logged in successfully to steamkit")

        @client.on("disconnected")
        def handle_disconnect():
            print("Disconnected.")

            if self.logged_on_once:
                print("Reconnecting...")
                client.reconnect(maxdelay=30)

    def login(self):
        self.steam.anonymous_login()

    def close(self):
        if self.steam.logged_on:
            self.logged_on_once = False
            print("Logout")
            self.steam.logout()
        if self.steam.connected:
            self.steam.disconnect()

    def get_product_info(self, appids=[]):
        resp = self.steam.send_job_and_wait(MsgProto(EMsg.ClientPICSProductInfoRequest),
                                            {
            'apps': map(lambda x: {'appid': x}, appids),
        },
            timeout=10
        )

        if not resp:
            return {}

        resp = proto_to_dict(resp)

        for app in resp.get('apps', []):
            app['appinfo'] = vdf.loads(
                app.pop('buffer')[:-1].decode('utf-8', 'replace'))['appinfo']
            app['sha'] = hexlify(app['sha']).decode('utf-8')

        return resp

    def get_changes(self, change_num):
        return self.steam.get_changes_since(change_number=change_num, app_changes=True, package_changes=False)

As I said before the client gets disconnected seemingly randomly and then after it reconnects the get_product_info() returns empty for some reason.

If you need additional code, please let me know and I will happily provide them. Thank you.

rossengeorgiev commented 4 years ago

This is project is not SteamKit. That is a different library. Steam will kick you out if you are sending bad data, or spamming. It up to you find what the limits are. You should probably use the library get_product_info() method as that is implemented correctly.

vBubbaa commented 4 years ago

Thank you for the information. I am currently using the get_product_info() as used in your SimpleWebApi recipe, is there another way you mean I should be using it (that is different from your recipe)?

rossengeorgiev commented 4 years ago

https://steam.readthedocs.io/en/latest/api/steam.client.html?highlight=get_product_info#steam.client.SteamClient.get_product_info

vBubbaa commented 4 years ago

Thank you very much, I will close this issue. Appreciate the help!