AttributeError: 'TwoCaptcha' object has no attribute 'recaptcha'

Viewed 2906

I try to make a solve bypass captcha but is not working.

  
import requests
import bs4
from twocaptcha import TwoCaptcha
import os

TwoCaptcha_api_key = ""
renew_url = ""
renew_session = requests.session()
renew_request = renew_session.get(renew_url)
renew_content = renew_request._content
renew_soup = bs4.BeautifulSoup(renew_content, 'lxml')

renew_sitekey = renew_soup.find('div', {"class":"g-recaptcha"})['data-sitekey']

renew_token = renew_soup.find('input', {"name":"_token"})['value']
solve = TwoCaptcha(TwoCaptcha_api_key)
result = solve.recaptcha(
    sitekey=renew_sitekey,
    url=renew_url)

recaptcha_response = result['code']
postdata = {"username": "AAAAAAA", "g-recaptcha-response": f"{recaptcha_response}", "_token": f"{renew_token}" }
renew_post = renew_session.post(renew_url, data=postdata)
print(renew_post)

And i got this error

Traceback (most recent call last):<br>
  File "", line 18, in <module><br>
    result = solve.recaptcha(<br>
AttributeError: 'TwoCaptcha' object has no attribute 'recaptcha'
3 Answers

The function is called solve_recaptcha(), not recaptcha. (see [README])1

Next time when you meet this error, you can look for the original code, the docs, or you can add a call to dir() to see the available members/methods:

solve = ...
print dir(solve)

In Ide pycharm or VS Go to terminal and past this code "pip3 install 2captcha-python" It will look like this PS C:\Users\PycharmProjects\test> pip3 install 2captcha-python It will solve your problem

Related