ValvePython / steam

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

[BUG] user state is always EPersonaState.Offline #379

Closed The0nix closed 2 years ago

The0nix commented 2 years ago

Description I login to a client using cli_login and when I try to get any user from my friendlist, his state is always EPersonaState.Offline even if he is currently playing. rich_presence is also empty. If I access the user via client.get_user(steam_id), the state is also EPersonaState.Offline.

Steps to Reproduce the behavior e.g.

>>> from steam.client import SteamClient
>>> client = SteamClient()
>>> client.cli_login()
*login*
>>> for user in client.friends:
>>>    print(user)
<SteamUser(76561197988455464, EFriendRelationship.Friend, EPersonaState.Offline)>
<SteamUser(76561197988741908, EFriendRelationship.Friend, EPersonaState.Offline)>
<SteamUser(76561197997584155, EFriendRelationship.Friend, EPersonaState.Offline)>
<SteamUser(76561198006010809, EFriendRelationship.Friend, EPersonaState.Offline)>
... (everyone is EPersonaState.Offline)

Expected behavior State depicts the real state, rich_presence contains necessary information

Screenshots If applicable, add screenshots to help explain your problem.

Versions Report

python -m steam.versions_report `python -m steam.versions_report` says No module named steam.versions_report pip list says `steam` is 1.2.0 I installed with `pip install -U 'steam[client]'`
The0nix commented 2 years ago

I installed version 1.1.1 and everything works there.

UPD: Nope, it only works every other time

rossengeorgiev commented 2 years ago

Most likely there is enough time for presence data to be requested and arrive before you try listing the users.

Try waiting with client.friends.wait_event(client.friends.EVENT_READY) before the loop

The0nix commented 2 years ago

Thank you for a swift reply! That does not seem to work, however:

Code ``` from steam.client import SteamClient client = SteamClient() @client.friends.on(client.friends.EVENT_READY) def print_friends_info(): for user in client.friends: try: print(user.state) except AttributeError as e: print(e) client.cli_login() try: client.run_forever() except KeyboardInterrupt: client.logout() raise SystemExit ```
Output ``` 'NoneType' object has no attribute 'persona_state' 'NoneType' object has no attribute 'persona_state' 'NoneType' object has no attribute 'persona_state' 'NoneType' object has no attribute 'persona_state' 'NoneType' object has no attribute 'persona_state' 'NoneType' object has no attribute 'persona_state' 'NoneType' object has no attribute 'persona_state' 'NoneType' object has no attribute 'persona_state' ... ```

(If I use client.friends.wait_event(client.friends.EVENT_READY), the event seems to happen before this code.so the wait hangs)

rossengeorgiev commented 2 years ago

Yeah, that can happen you can check if it already ready before waiting:

if not client.friends.ready:
    client.friends.wait_event(client.friends.EVENT_READY)

In your example where you register a callback, you will have to define it earlier. Ideally before logging in.

rossengeorgiev commented 2 years ago

Considering this as resolved