Facing a problem in solving captcha using a service

Artem

New member
I grab the site-key using a some-what hardcoded method, but since the len is always the same it's ok. After that I use the 2captcha API Documentation so that I can POST the key and GET the token for the captcha back. I face two major problems: 1) I always get the site-key wrong error, but the sitekey is correct according to their example (their sitekey is 40chars long and my sitekeys are 40 too) 2) I tried creating a POST function externally and trying it out seeing if it is a bug, but using the Py2Captcha documentation I always get the following error:

This is captcha key grabbing.

Code:
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Captcha Key~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
url=driver.find_element_by_css_selector("iframe[role='presentation']").get_attribute('src')
print(url)
keygoogle = url[53:93]
print('Site Key = ', keygoogle)

This is the captcha key solving block:
Code:
answer = ""
answer_id = 0
api_key = '--------------------------------'
data_post = {'key': api_key, 'method': 'userrecaptcha', 'googlekey': keygoogle, "pageurl": mainurl}
response = requests.post(url = 'https://2captcha.com/in.php', data = data_post )
print(response)
print("Waiting for server response.")
for x in range(15):
    time.sleep(1)
    if x == 5:
        print('Downloading info..')
    elif x == 10:
        print('Processing info..')
    elif x == 14:
        print('Solving captcha..')
data_request = {
    'key': api_key,
    'action': answer,
    'id': answer_id,
}
requests.get(url ='https://2captcha.com/res.php', data=data_request)
print(answer)

def captcha():
    google_key = keygoogle
    url = mainurl
    client = TwoCaptchaClient(client_key=api_key)
    task = GoogleReCaptchaV2Task(googlekey=google_key, pageurl=mainurl)
    job = client.create_task(task)
    token = job.get_solution_response()
    return token
print(captcha())

What I haven't included is the part where the token gets posted into the answer field, I am not sure how to do that yet but I will find a way for sure!

EDIT: This is the value I get from printing this:

response = requests.post(url = 'https://2captcha.com/in.php', data = data_post )

And this is the value I get from print('Site Key = ', keygoogle)

Site Key = Lc3HAsUAAAAACsN7CgY9MMVxo2M09n_e4heJEiZ&
 

85go

New member
This is my way of grabbing the correct key:
Code:
url=driver.find_element_by_css_selector("iframe[role='presentation']").get_attribute('src')
keygoogle = url[52:92]

And this is my POST function:
Code:
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Captcha Solve~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer = ""
answer_id = 0
data_post = {'key': api_key, 'method': 'userrecaptcha', 'googlekey': keygoogle, "pageurl": mainurl}
response = requests.post(url = 'https://2captcha.com/in.php', data = data_post )
response = response.text[3:]
print("Waiting for server response.")
for x in range(30):
    time.sleep(1)
    if x == 8:
        print('Downloading info..')
    elif x == 15:
        print('Processing info..')
data_request = {'key': api_key,'id': int(response),'action': 'get'}
response = requests.get(url='https://2captcha.com/res.php', params=data_request)
token = response.text.split('|')[0]
while response.text == 'CAPCHA_NOT_READY':
    print('Waiting for Capcha..')
    time.sleep(5)
    response = requests.get(url='https://2captcha.com/res.php', params=data_request)
    token = response
print(token)