Использование запросов Python к POST 2Captcha

Я пытаюсь использовать запросы POST к API 2captcha. Я следовал инструкциям на обоих сайтах, но исключение в postCaptcha всегда возникает из-за ошибки ERROR_ZERO_CAPTCHA_FILESIZE. Я включил связанные функции для большего контекста.

 def pullCaptcha(self, element, path):
        # Gets captcha image
        location = element.location
        size = element.size
        # saves screenshot of entire page
        self.driver.save_screenshot(path)

        image = Image.open(path)
        image = image.crop((520, 405, 635, 440))  # defines crop points
        image.save(path, 'png')  # saves new cropped image

        with open(path, "rb") as image_file:
            im = image_file.read()
            return im

def pullCaptcha(self, element, path):
        # Gets captcha image
        location = element.location
        size = element.size
        # saves screenshot of entire page
        self.driver.save_screenshot('hiha.png')
        self.driver.save_screenshot(path)

        left = location['x']
        top = location['y'] + 140
        right = location['x'] + size['width']
        bottom = location['y'] + size['height'] + 140



        image = Image.open(path)
        image = image.crop((520, 405, 635, 440))  # defines crop points
        image.save(path, 'png')  # saves new cropped image

        with open(path, "rb") as image_file:
            im = image_file.read()
            return im

def postCaptcha(self, image):
        params = {'json': 1, 'key': self.settings["captchaKey"],
                  'method': 'post', 'files': {'file': image}}

        response = requests.post(self.settings["captchaPOST"],
                                     timeout=5, data=params)
        print(response.text)
        if 'ERROR' in response.text:
            raise Exception('Captcha Error')
        return response.json()['request']

0 ответов

Другие вопросы по тегам