Steam 2FA 持续投掷 "Failed to get a web session"

Steam 2FA throwing "Failed to get a web session" consistantly

我正在使用 Steam 的 python 库创建一个用于生成 2FA 代码的应用程序。问题是每当我尝试添加 phone 号码或向所述帐户添加 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

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

感谢你们的帮助。

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

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

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