ValvePython / dota2

🐸 Python package for interacting with Dota 2 Game Coordinator
http://dota2.readthedocs.io
204 stars 32 forks source link

Request profile card example #4

Closed IlyaAndr closed 8 years ago

IlyaAndr commented 8 years ago

I'm trying to run simple example to request profile card. The issue is that every time i fill in Email code it asks for it again (and again). I'm absolutely sure that the code is correct. I believe the problem is that client is disconnected for some reason but i don't understand why it happens. So here is the code snippet:

from steam import SteamClient
from dota2 import Dota2Client
from steam.enums import EResult
from steam.enums.emsg import EMsg

import logging

logging.basicConfig(format='[%(asctime)s] %(levelname)s %(name)s: %(message)s', level=logging.DEBUG)

client = SteamClient()
dota = Dota2Client(client)

logOnDetails = {
    'username': 'my_username',
    'password': 'my_password',
}

@client.on('error')
def print_error(result):
  print "Error:", EResult(result)

@client.on('auth_code_required')
def auth_code_prompt(is_2fa, code_mismatch):
  print 'auth_code_prompt'
  if is_2fa:
    code = raw_input("Enter 2FA Code: ")
    client.login(logOnDetails['username'], logOnDetails['password'], two_factor_code=code)
  else:
    code = raw_input("Enter Email Code: ")
    client.login(logOnDetails['username'], logOnDetails['password'], auth_code=code)

@client.on('connected')
def login():
  print 'login'
  client.login(logOnDetails['username'], logOnDetails['password'])

@client.on('logged_on')
def start_dota():
  print 'start_dota'
  dota.launch()

@dota.on('ready')
def fetch_profile_card():
  print 'fetch_profile_card'
  dota.request_profile_card(70388657)

@dota.on('profile_card')
def print_profile_card(account_id, profile_card):
  if account_id == 70388657:
    print str(profile_card)

try:
  client.connect()
  client.run_forever()
except KeyboardInterrupt:
  client.logout()

And the logs:

[2016-08-16 09:58:08,233] DEBUG CMServerList: Bootstraping from builtin list
[2016-08-16 09:58:08,234] DEBUG CMServerList: Added 30 new CM addresses.
[2016-08-16 09:58:08,657] DEBUG SteamClient: Connect initiated.
[2016-08-16 09:58:08,657] DEBUG Connection: Attempting connection to ('162.254.197.42', 27018)
[2016-08-16 09:58:08,688] DEBUG Connection: Connected.
[2016-08-16 09:58:08,688] DEBUG SteamClient: Emit event: 'connected'
login
[2016-08-16 09:58:08,689] DEBUG SteamClient: Attempting login
[2016-08-16 09:58:08,719] DEBUG SteamClient: Incoming: <Msg <EMsg.ChannelEncryptRequest: 1303>>
[2016-08-16 09:58:08,719] DEBUG SteamClient: Emit event: <EMsg.ChannelEncryptRequest: 1303>
[2016-08-16 09:58:08,720] DEBUG SteamClient: Securing channel
[2016-08-16 09:58:08,721] DEBUG SteamClient: Outgoing: <Msg <EMsg.ChannelEncryptResponse: 1304>>
[2016-08-16 09:58:08,769] DEBUG SteamClient: Incoming: <Msg <EMsg.ChannelEncryptResult: 1305>>
[2016-08-16 09:58:08,769] DEBUG SteamClient: Emit event: <EMsg.ChannelEncryptResult: 1305>
[2016-08-16 09:58:08,770] DEBUG SteamClient: Channel secured
[2016-08-16 09:58:08,770] DEBUG SteamClient: Emit event: 'channel_secured'
[2016-08-16 09:58:08,771] DEBUG SteamClient: Outgoing: <MsgProto <EMsg.ClientLogon: 5514>>
[2016-08-16 09:58:09,295] DEBUG SteamClient: Incoming: <MsgProto <EMsg.Multi: 1>>
[2016-08-16 09:58:09,295] DEBUG SteamClient: Emit event: <EMsg.Multi: 1>
[2016-08-16 09:58:09,295] DEBUG SteamClient: Multi: Unpacking
[2016-08-16 09:58:09,296] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientLogOnResponse: 751>>
[2016-08-16 09:58:09,296] DEBUG SteamClient: Emit event: <EMsg.ClientLogOnResponse: 751>
[2016-08-16 09:58:09,296] DEBUG Connection: Connection error (reader).
[2016-08-16 09:58:09,296] DEBUG Connection: Disconnected.
[2016-08-16 09:58:09,297] DEBUG SteamClient: Emit event: 'error'
[2016-08-16 09:58:09,297] DEBUG SteamClient: Emit event: 'disconnected'
[2016-08-16 09:58:09,298] DEBUG SteamClient: Emit event: 'auth_code_required'
Error: EResult.AccountLogonDenied
auth_code_prompt
Enter Email Code: WQK5Y
[2016-08-16 09:58:23,062] DEBUG SteamClient: Attempting login
[2016-08-16 09:58:23,063] DEBUG SteamClient: Connect initiated.
[2016-08-16 09:58:23,063] DEBUG Connection: Attempting connection to ('155.133.242.8', 27020)
[2016-08-16 09:58:23,104] DEBUG Connection: Connected.
[2016-08-16 09:58:23,104] DEBUG SteamClient: Emit event: 'connected'
login
[2016-08-16 09:58:23,105] DEBUG SteamClient: Attempting login
[2016-08-16 09:58:23,144] DEBUG SteamClient: Incoming: <Msg <EMsg.ChannelEncryptRequest: 1303>>
[2016-08-16 09:58:23,144] DEBUG SteamClient: Emit event: <EMsg.ChannelEncryptRequest: 1303>
[2016-08-16 09:58:23,144] DEBUG SteamClient: Securing channel
[2016-08-16 09:58:23,145] DEBUG SteamClient: Outgoing: <Msg <EMsg.ChannelEncryptResponse: 1304>>
[2016-08-16 09:58:23,191] DEBUG SteamClient: Incoming: <Msg <EMsg.ChannelEncryptResult: 1305>>
[2016-08-16 09:58:23,191] DEBUG SteamClient: Emit event: <EMsg.ChannelEncryptResult: 1305>
[2016-08-16 09:58:23,192] DEBUG SteamClient: Channel secured
[2016-08-16 09:58:23,192] DEBUG SteamClient: Emit event: 'channel_secured'
[2016-08-16 09:58:23,192] DEBUG SteamClient: Outgoing: <MsgProto <EMsg.ClientLogon: 5514>>
[2016-08-16 09:58:23,194] DEBUG SteamClient: Outgoing: <MsgProto <EMsg.ClientLogon: 5514>>
[2016-08-16 09:58:23,735] DEBUG SteamClient: Incoming: <MsgProto <EMsg.Multi: 1>>
[2016-08-16 09:58:23,735] DEBUG SteamClient: Emit event: <EMsg.Multi: 1>
[2016-08-16 09:58:23,735] DEBUG SteamClient: Multi: Unpacking
[2016-08-16 09:58:23,736] DEBUG SteamClient: Multi: Decompressing payload (3275 -> 5217)
[2016-08-16 09:58:23,737] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientServersAvailable: 5501>>
[2016-08-16 09:58:23,737] DEBUG SteamClient: Emit event: <EMsg.ClientServersAvailable: 5501>
[2016-08-16 09:58:23,740] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientServersAvailable: 5501>>
[2016-08-16 09:58:23,740] DEBUG SteamClient: Emit event: <EMsg.ClientServersAvailable: 5501>
[2016-08-16 09:58:23,740] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientServersAvailable: 5501>>
[2016-08-16 09:58:23,741] DEBUG SteamClient: Emit event: <EMsg.ClientServersAvailable: 5501>
[2016-08-16 09:58:23,741] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientLogOnResponse: 751>>
[2016-08-16 09:58:23,741] DEBUG SteamClient: Emit event: <EMsg.ClientLogOnResponse: 751>
[2016-08-16 09:58:23,741] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientAccountInfo: 768>>
[2016-08-16 09:58:23,742] DEBUG SteamClient: Emit event: <EMsg.ClientAccountInfo: 768>
[2016-08-16 09:58:23,742] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientAccountInfo: 768>>
[2016-08-16 09:58:23,742] DEBUG SteamClient: Emit event: <EMsg.ClientAccountInfo: 768>
[2016-08-16 09:58:23,742] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientEmailAddrInfo: 5456>>
[2016-08-16 09:58:23,742] DEBUG SteamClient: Emit event: <EMsg.ClientEmailAddrInfo: 5456>
[2016-08-16 09:58:23,742] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientFriendsList: 767>>
[2016-08-16 09:58:23,742] DEBUG SteamClient: Emit event: <EMsg.ClientFriendsList: 767>
[2016-08-16 09:58:23,742] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientFriendsGroupsList: 5553>>
[2016-08-16 09:58:23,743] DEBUG SteamClient: Emit event: <EMsg.ClientFriendsGroupsList: 5553>
[2016-08-16 09:58:23,743] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientPlayerNicknameList: 5587>>
[2016-08-16 09:58:23,743] DEBUG SteamClient: Emit event: <EMsg.ClientPlayerNicknameList: 5587>
[2016-08-16 09:58:23,743] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientLicenseList: 780>>
[2016-08-16 09:58:23,743] DEBUG SteamClient: Emit event: <EMsg.ClientLicenseList: 780>
[2016-08-16 09:58:23,743] DEBUG SteamClient: Incoming: <Msg <EMsg.ClientUpdateGuestPassesList: 798>>
[2016-08-16 09:58:23,743] DEBUG SteamClient: Emit event: <EMsg.ClientUpdateGuestPassesList: 798>
[2016-08-16 09:58:23,743] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientWalletInfoUpdate: 5528>>
[2016-08-16 09:58:23,743] DEBUG SteamClient: Emit event: <EMsg.ClientWalletInfoUpdate: 5528>
[2016-08-16 09:58:23,744] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientGameConnectTokens: 779>>
[2016-08-16 09:58:23,744] DEBUG SteamClient: Emit event: <EMsg.ClientGameConnectTokens: 779>
[2016-08-16 09:58:23,744] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientSessionToken: 850>>
[2016-08-16 09:58:23,744] DEBUG SteamClient: Emit event: <EMsg.ClientSessionToken: 850>
[2016-08-16 09:58:23,744] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientIsLimitedAccount: 5430>>
[2016-08-16 09:58:23,744] DEBUG SteamClient: Emit event: <EMsg.ClientIsLimitedAccount: 5430>
[2016-08-16 09:58:23,744] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientCMList: 783>>
[2016-08-16 09:58:23,745] DEBUG SteamClient: Emit event: <EMsg.ClientCMList: 783>
[2016-08-16 09:58:23,745] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientServerList: 880>>
[2016-08-16 09:58:23,745] DEBUG SteamClient: Emit event: <EMsg.ClientServerList: 880>
[2016-08-16 09:58:23,745] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientRequestedClientStats: 5480>>
[2016-08-16 09:58:23,745] DEBUG SteamClient: Emit event: <EMsg.ClientRequestedClientStats: 5480>
[2016-08-16 09:58:23,746] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientServerList: 880>>
[2016-08-16 09:58:23,746] DEBUG SteamClient: Emit event: <EMsg.ClientServerList: 880>
[2016-08-16 09:58:23,746] DEBUG SteamClient: Incoming: <Msg <EMsg.ClientVACBanStatus: 782>>
[2016-08-16 09:58:23,746] DEBUG SteamClient: Emit event: <EMsg.ClientVACBanStatus: 782>
[2016-08-16 09:58:23,747] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientUpdateMachineAuth: 5537>>
[2016-08-16 09:58:23,747] DEBUG SteamClient: Emit event: <EMsg.ClientUpdateMachineAuth: 5537>
[2016-08-16 09:58:23,747] DEBUG SteamClient: Logon completed
[2016-08-16 09:58:23,747] DEBUG SteamClient: Heartbeat started.
[2016-08-16 09:58:23,747] DEBUG SteamClient: Emit event: 'logged_on'
[2016-08-16 09:58:23,748] DEBUG SteamClient.friends: Emit event: 'ready'
[2016-08-16 09:58:23,748] DEBUG CMServerList: List cleared.
[2016-08-16 09:58:23,748] DEBUG SteamClient: Updating CM list
[2016-08-16 09:58:23,748] DEBUG CMServerList: Added 80 new CM addresses.
[2016-08-16 09:58:23,749] DEBUG SteamClient: Outgoing: <MsgProto <EMsg.ClientChangeStatus: 716>>
start_dota
[2016-08-16 09:58:23,749] DEBUG SteamClient: Outgoing: <MsgProto <EMsg.ClientGamesPlayed: 742>>
[2016-08-16 09:58:23,750] DEBUG Dota2Client: Outgoing: <EGCBaseClientMsg.EMsgGCClientHello: 4006>
[2016-08-16 09:58:23,750] DEBUG SteamClient: Outgoing: <MsgProto <EMsg.ClientToGC: 5452>>
[2016-08-16 09:58:23,896] DEBUG SteamClient: Incoming: <MsgProto <EMsg.Multi: 1>>
[2016-08-16 09:58:23,897] DEBUG SteamClient: Emit event: <EMsg.Multi: 1>
[2016-08-16 09:58:23,897] DEBUG SteamClient: Multi: Unpacking
[2016-08-16 09:58:23,898] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientServersAvailable: 5501>>
[2016-08-16 09:58:23,898] DEBUG SteamClient: Emit event: <EMsg.ClientServersAvailable: 5501>
[2016-08-16 09:58:24,136] DEBUG SteamClient: Incoming: <MsgProto <EMsg.Multi: 1>>
[2016-08-16 09:58:24,137] DEBUG SteamClient: Emit event: <EMsg.Multi: 1>
[2016-08-16 09:58:24,137] DEBUG SteamClient: Multi: Unpacking
[2016-08-16 09:58:24,147] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ServiceMethod: 146>>
[2016-08-16 09:58:24,148] DEBUG SteamClient: Emit event: <EMsg.ServiceMethod: 146>
[2016-08-16 09:58:24,148] DEBUG SteamClient.unified_messages: Emit event: u'PlayerClient.NotifyLastPlayedTimes#1'
[2016-08-16 09:58:25,184] DEBUG SteamClient: Incoming: <MsgProto <EMsg.Multi: 1>>
[2016-08-16 09:58:25,184] DEBUG SteamClient: Emit event: <EMsg.Multi: 1>
[2016-08-16 09:58:25,185] DEBUG SteamClient: Multi: Unpacking
[2016-08-16 09:58:25,185] DEBUG SteamClient: Multi: Decompressing payload (218 -> 266)
[2016-08-16 09:58:25,185] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientNewLoginKey: 5463>>
[2016-08-16 09:58:25,185] DEBUG SteamClient: Emit event: <EMsg.ClientNewLoginKey: 5463>
[2016-08-16 09:58:25,186] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientPlayingSessionState: 9600>>
[2016-08-16 09:58:25,186] DEBUG SteamClient: Emit event: <EMsg.ClientPlayingSessionState: 9600>
[2016-08-16 09:58:25,186] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientGameConnectTokens: 779>>
[2016-08-16 09:58:25,186] DEBUG SteamClient: Emit event: <EMsg.ClientGameConnectTokens: 779>
[2016-08-16 09:58:25,187] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientPersonaState: 766>>
[2016-08-16 09:58:25,187] DEBUG SteamClient: Emit event: <EMsg.ClientPersonaState: 766>
[2016-08-16 09:58:25,187] DEBUG SteamClient: Outgoing: <MsgProto <EMsg.ClientNewLoginKeyAccepted: 5464>>
[2016-08-16 09:58:25,188] DEBUG SteamClient: Emit event: 'new_login_key'
[2016-08-16 09:58:25,254] DEBUG SteamClient: Incoming: <MsgProto <EMsg.Multi: 1>>
[2016-08-16 09:58:25,254] DEBUG SteamClient: Emit event: <EMsg.Multi: 1>
[2016-08-16 09:58:25,254] DEBUG SteamClient: Multi: Unpacking
[2016-08-16 09:58:25,255] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientLogOnResponse: 751>>
[2016-08-16 09:58:25,255] DEBUG SteamClient: Emit event: <EMsg.ClientLogOnResponse: 751>
[2016-08-16 09:58:25,255] DEBUG Connection: Connection error (reader).
[2016-08-16 09:58:25,256] DEBUG Connection: Disconnected.
[2016-08-16 09:58:25,256] DEBUG SteamClient: Emit event: 'disconnected'
[2016-08-16 09:58:25,257] DEBUG SteamClient: Emit event: 'error'
[2016-08-16 09:58:25,257] DEBUG SteamClient: Emit event: 'auth_code_required'
Error: EResult.AccountLogonDenied
auth_code_prompt
Enter Email Code:

Thanks in advance!

rossengeorgiev commented 8 years ago

You need to setup a location for credentials, so a sentry file can be created. After the fisrt login, it won't ask for email codes again. For example, client.set_credential_location("~/steam_credentials")

http://steam.readthedocs.io/en/stable/api/steam.client.html#steam.client.SteamClient.set_credential_location

You can run 2 clients with dota started. I suspect you have dota running. When SteamClient attempts to start dota again, it gets disconnected.

IlyaAndr commented 8 years ago

Thanks for your help! So with setting credential location i'm not asked for email code again but client still disconnects. So last lines are:

[2016-08-16 12:10:06,559] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientServersAvailable: 5501>>
[2016-08-16 12:10:06,559] DEBUG SteamClient: Emit event: <EMsg.ClientServersAvailable: 5501>
[2016-08-16 12:10:07,327] DEBUG SteamClient: Incoming: <MsgProto <EMsg.Multi: 1>>
[2016-08-16 12:10:07,327] DEBUG SteamClient: Emit event: <EMsg.Multi: 1>
[2016-08-16 12:10:07,327] DEBUG SteamClient: Multi: Unpacking
[2016-08-16 12:10:07,327] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientNewLoginKey: 5463>>
[2016-08-16 12:10:07,328] DEBUG SteamClient: Emit event: <EMsg.ClientNewLoginKey: 5463>
[2016-08-16 12:10:07,328] DEBUG SteamClient: Incoming: <MsgProto <EMsg.ClientLoggedOff: 757>>
[2016-08-16 12:10:07,328] DEBUG SteamClient: Emit event: <EMsg.ClientLoggedOff: 757>
[2016-08-16 12:10:07,328] DEBUG Connection: Connection error (reader).
[2016-08-16 12:10:07,328] DEBUG Connection: Disconnected.
[2016-08-16 12:10:07,328] DEBUG SteamClient: Emit event: 'disconnected'

I don't have dota client installed on current machine. Is that required?

rossengeorgiev commented 8 years ago

Are you connected elsewhere on the same account?

IlyaAndr commented 8 years ago

I believe no (it's my private steam account and i didn't share it with anyone).

rossengeorgiev commented 8 years ago

If the account it logged on somewhere, and running dota, you will get disconnected.

IlyaAndr commented 8 years ago

Ok, thanks for your help! I'll double check it!