Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_http_error(self, mrs_mock):
mm = mrs_mock.return_value = mock.MagicMock()
mm.post.side_effect = requests.exceptions.ConnectTimeout('test')
with self.assertRaises(wa.HTTPError):
wa.WebAuth('a', 'b').login()
mm.post.reset_mock()
mm.post.side_effect = requests.exceptions.ReadTimeout('test')
with self.assertRaises(wa.HTTPError):
wa.WebAuth('c', 'd').login()
def user_pass_only_success(u, p):
wa.WebAuth(u, p).login()
def user_pass_only_fail(u, p):
try:
wa.WebAuth(u, p).login()
except wa.LoginIncorrect:
pass
def test_http_error(self, mrs_mock):
mm = mrs_mock.return_value = mock.MagicMock()
mm.post.side_effect = requests.exceptions.ConnectTimeout('test')
with self.assertRaises(wa.HTTPError):
wa.WebAuth('a', 'b').login()
mm.post.reset_mock()
mm.post.side_effect = requests.exceptions.ReadTimeout('test')
with self.assertRaises(wa.HTTPError):
wa.WebAuth('c', 'd').login()
def steam_login():
# Steam login function by sumfun4WF
user = wa.WebAuth(email, password)
try:
user.login()
except wa.CaptchaRequired:
print("Please complete the captcha: "+user.captcha_url)
captcha_code=input("Please input the captcha response code: ")
user.login(captcha=captcha_code)
except wa.EmailCodeRequired:
email_code=input("Please input the email verification code: ")
user.login(email_code=email_code)
except wa.TwoFactorCodeRequired:
tfa_code=input("Please input the 2FA code: ")
user.login(twofactor_code=tfa_code)
# Copy cookies to session
s.cookies.update(user.session.cookies)
while True:
try:
if isinstance(exp, CaptchaRequired):
prompt = "Solve CAPTCHA at %s\nCAPTCHA code: " % self.captcha_url
captcha = _cli_input(prompt)
else:
captcha = ''
except EmailCodeRequired:
prompt = ("Enter email code: " if not email_code else
"Incorrect code. Enter email code: ")
email_code, twofactor_code = _cli_input(prompt), ''
except TwoFactorCodeRequired:
prompt = ("Enter 2FA code: " if not twofactor_code else
"Incorrect code. Enter 2FA code: ")
email_code, twofactor_code = '', _cli_input(prompt)
class MobileWebAuth(WebAuth):
"""Identical to :class:`WebAuth`, except it authenticates as a mobile device."""
oauth_token = None #: holds oauth_token after successful login
def _send_login(self, password='', captcha='', email_code='', twofactor_code=''):
data = {
'username': self.username,
"password": b64encode(pkcs1v15_encrypt(self.key, password.encode('ascii'))),
"emailauth": email_code,
"emailsteamid": str(self.steam_id) if email_code else '',
"twofactorcode": twofactor_code,
"captchagid": self.captcha_gid,
"captcha_text": captcha,
"loginfriendlyname": "python-steam webauth",
"rsatimestamp": self.timestamp,
"remember_login": 'true',
"donotcache": int(time() * 100000),
def login():
username = input("Steam Username: ")
steam_auth = wa.WebAuth(username)
steam_auth.cli_login()
save_cookies(steam_auth.session.cookies)
return steam_auth.session.cookies