Steam 2FA投掷"无法获得网络会话" consistantly

时间:2018-03-30 15:00:14

标签: python-3.x steam two-factor-authentication

我使用steam的python库创建了一个用于生成2FA代码的应用程序。问题是每当我尝试添加电话号码或向该帐户添加2FA时,Steam都会抛出此错误:

RuntimeError: Failed to get a web session. Try again in a few minutes
Fri Mar 30 08:39:04 2018 <Greenlet at 0x6e64580: handle_after_logon> failed with RuntimeError

是的,我等了几分钟,已经尝试了好几个小时。 这是我用来尝试此操作的代码:

from steam import SteamClient
from steam.enums.emsg import EMsg
from steam.guard import SteamAuthenticator

#Create our steamclient instance
client = SteamClient()

@client.on("logged_on")
def handle_after_logon():
    print("You are now Logged in.")
    #Setup Autenticator for our steamclient instance "client". "client" is our logged in SteamClient instance as requested by documentation
    sa = SteamAuthenticator(medium=client)
    #My account has no phone number
    print(sa.has_phone_number())
    #Adding phone number because I know ahead of time I don't have it
    sa.add_phone_number("myphonenumber with area code")
    sa.add()    # SMS code will be sent to account's phone number
    sa.secrets  # dict with authenticator secrets
    #We're gonna need these
    print(sa.secrets)
    sa.finalize(str(input("SMS CODE: ")))  # activate the authenticator
    sa.get_code()  # generate 2FA code for login
    sa.remove()  # removes the authenticator from the account

try:
    #Login to our steamclient instance
    client.cli_login("myusername","mypassword")

    #client.on("loggon_on") doesn't trigger without this
    client.run_forever()

#Allow us to logout using keyboard interrupt
except KeyboardInterrupt:
    if client.connected:
        client.logout()

由于2FA上缺少示例代码,我已尽力遵循文档,我已经查看了以下所有内容:

http://steam.readthedocs.io/en/latest/api/steam.client.html

http://steam.readthedocs.io/en/latest/api/steam.guard.html

https://github.com/ValvePython/steam/blob/master/recipes/1.Login/persistent_login.py

我觉得我的代码中只是一个愚蠢的错误,但阅读文档似乎并没有帮助我解决这个问题。

感谢你们的帮助。

1 个答案:

答案 0 :(得分:0)

我调试了一段时间,这是gevent的问题

我在剧本开头添加了这一行来修复它:

from gevent import monkey
monkey.patch_all(thread=False)