Skip to content

Instantly share code, notes, and snippets.

@musshorn
Last active January 28, 2021 10:49
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save musshorn/2156576c2754f8a4c9b43ccb674d5a5d to your computer and use it in GitHub Desktop.
Save musshorn/2156576c2754f8a4c9b43ccb674d5a5d to your computer and use it in GitHub Desktop.
Python script to redeem bulk steam keys
'''
Python3 Bulk Steam key importer
Requires the pip library 'steam'
Run `pip install steam` if you're unsure
Code expects a text file with keys line seperated. For example:
XXXXX-YYYYY-ZZZZZ
AAAAA-BBBBB-CCCCC
would be a valid file.
I'm not affiliated with Valve and use of this code is at your own risk.
'''
import json
import getpass
import steam.webauth as wa
keyFileName = "keys.txt"
user = wa.WebAuth("STEAM USERNAME GOES HERE", 'STEAM PASSWORD GOES HERE')
# Create a login session
try:
user.login()
except wa.CaptchaRequired:
print(user.captcha_url)
code = input("Please follow the captcha url, enter the code below:\n")
user.login(captcha=code)
except wa.EmailCodeRequired:
code = input("Please enter emailed 2FA code:\n")
user.login(email_code=code)
except wa.TwoFactorCodeRequired:
code = input("Please enter 2FA code from the Steam app on your phone:\n")
user.login(twofactor_code=code)
# Get the sesssion ID, required for the ajax key auth
sessionID = user.session.cookies.get_dict()["sessionid"]
keys = []
f = open(keyFileName)
for line in f:
keys.append(line)
# Iterate over keys, if you need faster than this for some unknown reason you've probably got the skill to make this faster.
for key in keys:
r = user.session.post('https://store.steampowered.com/account/ajaxregisterkey/', data={'product_key' : key, 'sessionid' : sessionID})
blob = json.loads(r.text)
# Success
if blob["success"] == 1:
for item in blob["purchase_receipt_info"]["line_items"]:
print("[ Redeemed ]", item["line_item_description"])
else:
# Error codes from https://steamstore-a.akamaihd.net/public/javascript/registerkey.js?v=qQS85n3B1_Bi&l=english
errorCode = blob["purchase_result_details"]
sErrorMessage = ""
if errorCode == 14:
sErrorMessage = 'The product code you\'ve entered is not valid. Please double check to see if you\'ve mistyped your key. I, L, and 1 can look alike, as can V and Y, and 0 and O.'
elif errorCode == 15:
sErrorMessage = 'The product code you\'ve entered has already been activated by a different Steam account. This code cannot be used again. Please contact the retailer or online seller where the code was purchased for assistance.'
elif errorCode == 53:
sErrorMessage = 'There have been too many recent activation attempts from this account or Internet address. Please wait and try your product code again later.'
elif errorCode == 13:
sErrorMessage = 'Sorry, but this product is not available for purchase in this country. Your product key has not been redeemed.'
elif errorCode == 9:
sErrorMessage = 'This Steam account already owns the product(s) contained in this offer. To access them, visit your library in the Steam client.'
elif errorCode == 24:
sErrorMessage = 'The product code you\'ve entered requires ownership of another product before activation.\n\nIf you are trying to activate an expansion pack or downloadable content, please first activate the original game, then activate this additional content.'
elif errorCode == 36:
sErrorMessage = 'The product code you have entered requires that you first play this game on the PlayStation®3 system before it can be registered.\n\nPlease:\n\n- Start this game on your PlayStation®3 system\n\n- Link your Steam account to your PlayStation®3 Network account\n\n- Connect to Steam while playing this game on the PlayStation®3 system\n\n- Register this product code through Steam.'
elif errorCode == 50:
sErrorMessage = 'The code you have entered is from a Steam Gift Card or Steam Wallet Code. Browse here: https://store.steampowered.com/account/redeemwalletcode to redeem it.'
else:
sErrorMessage = 'An unexpected error has occurred. Your product code has not been redeemed. Please wait 30 minutes and try redeeming the code again. If the problem persists, please contact <a href="https://help.steampowered.com/en/wizard/HelpWithCDKey">Steam Support</a> for further assistance.';
print("[ Error ]", sErrorMessage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment