AttributeError:“TwoCaptcha”对象没有属性“recaptcha”

Ash*_*cia 4 python

我尝试解决绕过验证码的问题,但不起作用。

  
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)
Run Code Online (Sandbox Code Playgroud)

我收到了这个错误

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

gsb*_*b22 14

我猜你正在谈论这个包https://pypi.org/project/2captcha-python/#solve-captcha来解决验证码。

我还猜测,您一定是使用某些 IDE 安装了这个包,而安装了错误的包。( https://pypi.org/project/TwoCaptcha/ ) 这是原始版本的包装器。

删除当前不正确的软件包pip uninstall TwoCaptcha并安装正确的软件包pip install 2captcha-python