webauth¶
This module simplifies the process of obtaining an authenticated session for steam websites.
After authentication is complete, 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 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', 'password')
try:
user.login()
except wa.CaptchaRequired:
print user.captcha_url
# ask a human to solve captcha
user.login(captcha='ABC123')
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/')
# OR
session = user.login()
session.get('https://store.steampowered.com/account/history')
Alternatively, if Steam Guard is not enabled on the account:
try:
session = wa.WebAuth('username', 'password').login()
except wa.HTTPError:
pass
The WebAuth
instance should be discarded once a session is obtained
as it is not reusable.
-
class
steam.webauth.
WebAuth
(username, password)¶ Bases:
object
-
key
= None¶
-
complete
= False¶ whether authentication has been completed successfully
-
captcha_gid
= -1¶
-
session
= None¶ requests.Session
(with auth cookies after auth is complete)
-
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
(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
- CaptchaRequired – when captcha is needed
- EmailCodeRequired – when email is needed
- TwoFactorCodeRequired – when 2FA is needed
- LoginIncorrect – wrong username or password
-
-
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.
EmailCodeRequired
¶
-
exception
steam.webauth.
TwoFactorCodeRequired
¶