首页 > 解决方案 > AttributeError:“TwoCaptcha”对象没有属性“recaptcha”

问题描述

我尝试解决绕过验证码但不工作。

  
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)

我得到了这个错误

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

标签: python

解决方案


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

我也在猜测,你一定是使用了一些 IDE 来安装这个安装了错误的包。( https://pypi.org/project/TwoCaptcha/ ) 这是原始的包装。

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


推荐阅读