Skip to content

Commit

Permalink
Enable automated captcha solving with 2captcha
Browse files Browse the repository at this point in the history
-cs flag to enable
-ck flag to specify 2captcha API key
-cds flag to specify the data-sitekey for PoGo captchas
  • Loading branch information
chowderchow committed Nov 10, 2016
1 parent b58e08b commit 13c10cf
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
69 changes: 67 additions & 2 deletions pogom/search.py
Expand Up @@ -414,6 +414,7 @@ def search_worker_thread(args, account_queue, account_failures, search_items_que

# only sleep when consecutive_fails reaches max_failures, overall fails for stat purposes
consecutive_fails = 0
consecutive_empties = 0

# Create the API instance this will use
if args.mock != '':
Expand All @@ -425,7 +426,7 @@ def search_worker_thread(args, account_queue, account_failures, search_items_que
log.debug("Using proxy %s", status['proxy_url'])
api.set_proxy({'http': status['proxy_url'], 'https': status['proxy_url']})

api.activate_signature(encryption_lib_path)
# api.activate_signature(encryption_lib_path)

# The forever loop for the searches
while True:
Expand All @@ -437,6 +438,37 @@ def search_worker_thread(args, account_queue, account_failures, search_items_que
account_failures.append({'account': account, 'last_fail_time': now(), 'reason': 'failures'})
break # exit this loop to get a new account and have the API recreated

if args.captcha_solving:

if consecutive_empties >= 2:
captcha_url = captcha_request(api)

if len(captcha_url) > 1:
status['message'] = 'Account {} is encountering a captcha, starting 2captcha sequence'.format(account['username'])
log.warning(status['message'])
captcha_token = token_request(args, status, captcha_url)

if 'ERROR' in captcha_token:
log.warning("Unable to resolve captcha, please check your 2captcha API key and/or wallet balance")
account_failures.append({'account': account, 'last_fail_time': now(), 'reason': 'catpcha failed to verify'})
break

else:
status['message'] = 'Retrieved captcha token, attempting to verify challenge for {}'.format(account['username'])
log.info(status['message'])
response = api.verify_challenge(token = captcha_token)

if 'success' in response['responses']['VERIFY_CHALLENGE']:
status['message'] = "Account {} successfully uncaptcha'd".format(account['username'])
log.info(status['message'])

else:
status['message'] = "Account {} failed verifyChallenge, putting away account for now".format(account['username'])
log.info(status['message'])
account_failures.append({'account': account, 'last_fail_time': now(), 'reason': 'catpcha failed to verify'})
break
time.sleep(1)

while pause_bit.is_set():
status['message'] = 'Scanning paused'
time.sleep(2)
Expand Down Expand Up @@ -509,7 +541,12 @@ def search_worker_thread(args, account_queue, account_failures, search_items_que
try:
parsed = parse_map(args, response_dict, step_location, dbq, whq, api)
search_items_queue.task_done()
status[('success' if parsed['count'] > 0 else 'noitems')] += 1
if parsed['count'] > 0:
status['success'] += 1
consecutive_empties = 0
else:
status['noitems'] += 1
consecutive_empties += 1
consecutive_fails = 0
status['message'] = 'Search at {:6f},{:6f} completed with {} finds'.format(step_location[0], step_location[1], parsed['count'])
log.debug(status['message'])
Expand Down Expand Up @@ -656,6 +693,34 @@ def gym_request(api, position, gym):
return False


def captcha_request(api):
captcha = {}
response = api.check_challenge()
captcha_url = response['responses']['CHECK_CHALLENGE']['challenge_url']
return captcha_url


def token_request(args, status, url):
s = requests.Session()
# Fetch the CAPTCHA_ID from 2captcha
try:
captcha_id = s.post("http://2captcha.com/in.php?key={}&method=userrecaptcha&googlekey={}&pageurl={}".format(args.captcha_key, args.captcha_dsk, url)).text.split('|')[1]
captcha_id = str(captcha_id)
# IndexError implies that the retuned response was a 2captcha error
except IndexError:
return 'ERROR'
status['message'] = 'Retrieved captcha ID: {}; now retrieving token'.format(captcha_id)
log.info(status['message'])
# Get the response, retry every 5 seconds if its not ready
recaptcha_response = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(args.captcha_key, captcha_id)).text
while 'CAPCHA_NOT_READY' in recaptcha_response:
log.info("Captcha token is not ready, retrying in 5 seconds")
time.sleep(5)
recaptcha_response = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(args.captcha_key, captcha_id)).text
token = str(recaptcha_response.split('|')[1])
return token


def calc_distance(pos1, pos2):
R = 6378.1 # km radius of the earth

Expand Down
8 changes: 8 additions & 0 deletions pogom/utils.py
Expand Up @@ -77,6 +77,14 @@ def get_args():
parser.add_argument('-enc', '--encounter',
help='Start an encounter to gather IVs and moves',
action='store_true', default=False)
parser.add_argument('-cs', '--captcha-solving',
help='Enables captcha solving',
action='store_true', default=False)
parser.add_argument('-ck', '--captcha-key',
help='2Captcha API key')
parser.add_argument('-cds', '--captcha-dsk',
help='PokemonGo captcha data-sitekey',
default="6LeeTScTAAAAADqvhqVMhPpr_vB9D364Ia-1dSgK")
parser.add_argument('-ed', '--encounter-delay',
help='Time delay between encounter pokemon in scan threads',
type=float, default=1)
Expand Down

0 comments on commit 13c10cf

Please sign in to comment.