webauth¶
This module simplifies the process of obtaining an authenticated session for steam websites.
After authentication is completed, a requests.Session
is created containing the auth cookies.
The session can be used to access steamcommunity.com
, store.steampowered.com
, and help.steampowered.com
.
Warning
A web session may expire randomly, or when you login from different IP address. Some pages will return status code 401 when that happens. Keep in mind if you are trying to write robust code.
Note
If you are using SteamClient
take a look at SteamClient.get_web_session()
Note
If you need to authenticate as a mobile device for things like trading confirmations
use MobileWebAuth
instead. The login process is identical, and in addition
you will get oauth_token
.
Example usage:
import steam.webauth as wa
user = wa.WebAuth('username')
# At a console, cli_login can be used to easily perform all login steps
session = user.cli_login('password')
session.get('https://store.steampowered.com/account/history')
# Or the login steps be implemented for other situation like so
try:
user.login('password')
except (wa.CaptchaRequired, wa.LoginIncorrect) as exp:
if isinstance(exp, LoginIncorrect):
# ask for new password
else:
password = self.password
if isinstance(exp, wa.CaptchaRequired):
print user.captcha_url
# ask a human to solve captcha
else:
captcha = None
user.login(password=password, captcha=captcha)
except wa.EmailCodeRequired:
user.login(email_code='ZXC123')
except wa.TwoFactorCodeRequired:
user.login(twofactor_code='ZXC123')
user.session.get('https://store.steampowered.com/account/history/')
-
class
steam.webauth.
WebAuth
(username, password='')¶ Bases:
object
-
key
= None¶
-
logged_on
= False¶ whether authentication has been completed successfully
-
captcha_gid
= -1¶
-
captcha_code
= ''¶
-
session
= None¶ requests.Session
(with auth cookies after auth is completed)
-
captcha_url
¶ If a captch is required this property will return url to the image, or
None
-
get_rsa_key
(username)¶ Get rsa key for a given username
Parameters: username ( str
) – usernameReturns: json response Return type: dict
Raises: HTTPError – any problem with http request, timeouts, 5xx, 4xx etc
-
login
(password='', captcha='', email_code='', twofactor_code='', language='english')¶ Attempts web login and returns on a session with cookies set
Parameters: Returns: a session on success and
None
otherwiseReturn type: requests.Session
,None
Raises: - HTTPError – any problem with http request, timeouts, 5xx, 4xx etc
- LoginIncorrect – wrong username or password
- CaptchaRequired – when captcha is needed
- CaptchaRequiredLoginIncorrect – when captcha is needed and login is incorrect
- EmailCodeRequired – when email is needed
- TwoFactorCodeRequired – when 2FA is needed
-
cli_login
(password='', captcha='', email_code='', twofactor_code='', language='english')¶ Generates CLI prompts to perform the entire login process
Parameters: Returns: a session on success and
None
otherwiseReturn type: requests.Session
,None
In [3]: user.cli_login() Enter password for 'steamuser': Solve CAPTCHA at https://steamcommunity.com/login/rendercaptcha/?gid=1111111111111111111 CAPTCHA code: 123456 Invalid password for 'steamuser'. Enter password: Solve CAPTCHA at https://steamcommunity.com/login/rendercaptcha/?gid=2222222222222222222 CAPTCHA code: abcdef Enter 2FA code: AB123 Out[3]: <requests.sessions.Session at 0x6fffe56bef0>
-
-
class
steam.webauth.
MobileWebAuth
(username, password='')¶ Bases:
steam.webauth.WebAuth
Identical to
WebAuth
, except it authenticates as a mobile device.-
oauth_token
= None¶ holds oauth_token after successful login
-
-
exception
steam.webauth.
HTTPError
¶
-
exception
steam.webauth.
LoginIncorrect
¶
-
exception
steam.webauth.
CaptchaRequired
¶
-
exception
steam.webauth.
CaptchaRequiredLoginIncorrect
¶ Bases:
steam.webauth.CaptchaRequired
,steam.webauth.LoginIncorrect
-
exception
steam.webauth.
EmailCodeRequired
¶
-
exception
steam.webauth.
TwoFactorCodeRequired
¶