python - Python 方法缺少一个参数,但似乎都在那里
问题描述
我想要做的是运行一段代码,该代码一次可以工作,但是当我加载项目时,验证码解决函数说我在函数中缺少一个参数,但我看不到在哪里。
代码:
这段代码:
elif action_to_take == "RECAPTCHA_V2":
selenium_field = self.execute_recaptcha_v2_solver(captcha_key, url_or_field_identifier)
self.write_to_debug_file("--> SOLVING RECAPTCHA V2 ...", _filename)
然后执行:
# this function executes the ReCaptcha solver ...
def execute_recaptcha_v2_solver(self, api_key, url_or_field_identifier):
solve_recaptcha_v2 = CaptchaReCaptchaSolver.solve_recaptcha(api_key,
self.extract_data_site_key(self.driver.page_source),
url_or_field_identifier)
javascript_code = 'document.getElementById("g-recaptcha-response").innerHTML = "{}"'.format(solve_recaptcha_v2)
return self.driver.execute_script(javascript_code)
哪个运行类:
class CaptchaReCaptchaSolver(object):
# noinspection PyMethodMayBeStatic
def solve_recaptcha(self, _captcha_api_key, _site_key, _url):
print(_captcha_api_key, _site_key, _url)
""" this function solves recaptcha using 2captcha.com """
try:
# p = '127.0.0.1:6969'
# p = {'http': 'http://' + p, 'https': 'https://' + p}
# send off requests ...
s = requests.Session()
cap_id = s.post('http://2captcha.com/in.php?key={}&method=userrecaptcha&googlekey={}&pageurl={}'.format(
_captcha_api_key, _site_key, _url)).text.split('|')[1]
rec_an = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(_captcha_api_key, cap_id)).text
# tell us what is going on ...
print("--> ReCAPTCHA V2 SOLVING")
print("--> SOLVING ...")
while "CAPTCHA_NOT_READY" in rec_an:
sleep(5)
rec_an = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(_captcha_api_key, cap_id)).text
rec_an = rec_an.split('|')[1]
# solved ...
print("--> " + rec_an)
print("--> SOLVED ...")
print("--> ReCAPTCHA V2 RESPONSE")
# payload ...
payload = {'key': 'value', 'gresponse': rec_an}
s.post(_url, payload)
# return ReCaptcha answer ...
return rec_an
except Exception as e:
print("2CAPTCHA.COM [ReCAPTCHA] ERROR: ", e)
错误是:
LINE 222 "selenium_field = self.execute_recaptcha_v2_solver(captcha_key, url_or_field_identifier)"): solve_recaptcha() missing 1 required positional argument: '_url'
类方法solve_recaptcha()
缺少它所说的参数,但我已经将它们打印出来并且它们都在那里,我是否遗漏了一些明显的东西?我看不出问题可能是什么,任何帮助将不胜感激。
解决方案
注意这里......CaptchaReCaptchaSolver.solve_recaptcha
这就是你如何调用静态类成员而不是实例。由于该方法的第一个参数是self
then 它需要在对象的实例上调用该函数。
这应该修复。
CaptchaReCaptchaSolver().solve_recaptch(...
现在你的最终代码是
# this function executes the ReCaptcha solver ...
def execute_recaptcha_v2_solver(self, api_key, url_or_field_identifier):
solve_recaptcha_v2 = CaptchaReCaptchaSolver().solve_recaptcha(api_key,
self.extract_data_site_key(self.driver.page_source),
url_or_field_identifier)
javascript_code = 'document.getElementById("g-recaptcha-response").innerHTML = "{}"'.format(solve_recaptcha_v2)
return self.driver.execute_script(javascript_code)
推荐阅读
- javascript - 如何将 video.removeEventListener 添加到代码中
- jquery - 请求参数为空,在提交带有图像的表单数据 AJAX 后
- c++ - 初始化自定义类 C++ 的二维数组
- ajax - 抛出异常:大文件上传 ASP.Net 核心上 System.Private.CoreLib.dll 中的“System.IO.InvalidDataException”
- html - 如何为选项创建多个选项
- python - 'dict' 对象没有属性 'META' 重定向错误
- postman - 邮递员将标题添加到上传的文件
- php - Functions.php 从 wordpress 仪表板返回消息
- java - Firebase 嵌套快照
- amazon-web-services - VSCode 调试器在本地调试 AWS Lambda 时无法解析不存在的文件