# Path: python_anticaptcha/base.py
# class AnticaptchaClient(object):
#     client_key = None
#     CREATE_TASK_URL = "/createTask"
#     TASK_RESULT_URL = "/getTaskResult"
#     BALANCE_URL = "/getBalance"
#     REPORT_IMAGE_URL = "/reportIncorrectImageCaptcha"
#     REPORT_RECAPTCHA_URL = "/reportIncorrectRecaptcha"
#     APP_STAT_URL = "/getAppStats"
#     SOFT_ID = 847
#     language_pool = "en"
#     response_timeout = 5
# 
#     def __init__(
#         self, client_key, language_pool="en", host="api.anti-captcha.com", use_ssl=True
#     ):
#         self.client_key = client_key
#         self.language_pool = language_pool
#         self.base_url = "{proto}://{host}/".format(
#             proto="https" if use_ssl else "http", host=host
#         )
#         self.session = requests.Session()
# 
#     @property
#     def client_ip(self):
#         if not hasattr(self, "_client_ip"):
#             self._client_ip = self.session.get(
#                 "https://api.myip.com", timeout=self.response_timeout
#             ).json()["ip"]
#         return self._client_ip
# 
#     def _check_response(self, response):
#         if response.get("errorId", False) == 11:
#             response[
#                 "errorDescription"
#             ] = "{} Your missing IP address is propably {}.".format(
#                 response["errorDescription"], self.client_ip
#             )
#         if response.get("errorId", False):
#             raise AnticaptchaException(
#                 response["errorId"], response["errorCode"], response["errorDescription"]
#             )
# 
#     def createTask(self, task):
#         request = {
#             "clientKey": self.client_key,
#             "task": task.serialize(),
#             "softId": self.SOFT_ID,
#             "languagePool": self.language_pool,
#         }
#         response = self.session.post(
#             urljoin(self.base_url, self.CREATE_TASK_URL),
#             json=request,
#             timeout=self.response_timeout,
#         ).json()
#         self._check_response(response)
#         return Job(self, response["taskId"])
# 
#     def createTaskSmee(self, task, timeout=MAXIMUM_JOIN_TIME):
#         """
#         Beta method to stream response from smee.io
#         """
#         response = self.session.head(
#             "https://smee.io/new", timeout=self.response_timeout
#         )
#         smee_url = response.headers["Location"]
#         task = task.serialize()
#         request = {
#             "clientKey": self.client_key,
#             "task": task,
#             "softId": self.SOFT_ID,
#             "languagePool": self.language_pool,
#             "callbackUrl": smee_url,
#         }
#         r = self.session.get(
#             url=smee_url,
#             headers={"Accept": "text/event-stream"},
#             stream=True,
#             timeout=(self.response_timeout, timeout),
#         )
#         response = self.session.post(
#             url=urljoin(self.base_url, self.CREATE_TASK_URL),
#             json=request,
#             timeout=self.response_timeout,
#         ).json()
#         self._check_response(response)
#         for line in r.iter_lines():
#             content = line.decode("utf-8")
#             if '"host":"smee.io"' not in content:
#                 continue
#             payload = json.loads(split(content, ":", 1)[1].strip())
#             if "taskId" not in payload["body"] or str(payload["body"]["taskId"]) != str(
#                 response["taskId"]
#             ):
#                 continue
#             r.close()
#             if task["type"] == "CustomCaptchaTask":
#                 payload["body"]["solution"] = payload["body"]["data"][0]
#             job = Job(client=self, task_id=response["taskId"])
#             job._last_result = payload["body"]
#             return job
# 
#     def getTaskResult(self, task_id):
#         request = {"clientKey": self.client_key, "taskId": task_id}
#         response = self.session.post(
#             urljoin(self.base_url, self.TASK_RESULT_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response
# 
#     def getBalance(self):
#         request = {
#             "clientKey": self.client_key,
#             "softId": self.SOFT_ID,
#         }
#         response = self.session.post(
#             urljoin(self.base_url, self.BALANCE_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response["balance"]
# 
#     def getAppStats(self, soft_id, mode):
#         request = {"clientKey": self.client_key, "softId": soft_id, "mode": mode}
#         response = self.session.post(
#             urljoin(self.base_url, self.APP_STAT_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response
# 
#     def reportIncorrectImage(self, task_id):
#         request = {"clientKey": self.client_key, "taskId": task_id}
#         response = self.session.post(
#             urljoin(self.base_url, self.REPORT_IMAGE_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response.get("status", False) != False
# 
#     def reportIncorrectRecaptcha(self, task_id):
#         request = {"clientKey": self.client_key, "taskId": task_id}
#         response = self.session.post(
#             urljoin(self.base_url, self.REPORT_RECAPTCHA_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response["status"] == "success"
# 
# Path: python_anticaptcha/tasks.py
# class FunCaptchaTask(ProxyMixin, FunCaptchaProxylessTask):
#     type = "FunCaptchaTask"


from six.moves.urllib import parse
from os import environ
from random import choice
from python_anticaptcha import AnticaptchaClient, FunCaptchaTask
import requests
import re


api_key = environ["KEY"]
site_key_pattern = 'public_key: "(.+?)",'
url = "https://client-demo.arkoselabs.com/solo-animals"
client = AnticaptchaClient(api_key)
session = requests.Session()


# Path: python_anticaptcha/base.py
# class AnticaptchaClient(object):
#     client_key = None
#     CREATE_TASK_URL = "/createTask"
#     TASK_RESULT_URL = "/getTaskResult"
#     BALANCE_URL = "/getBalance"
#     REPORT_IMAGE_URL = "/reportIncorrectImageCaptcha"
#     REPORT_RECAPTCHA_URL = "/reportIncorrectRecaptcha"
#     APP_STAT_URL = "/getAppStats"
#     SOFT_ID = 847
#     language_pool = "en"
#     response_timeout = 5
# 
#     def __init__(
#         self, client_key, language_pool="en", host="api.anti-captcha.com", use_ssl=True
#     ):
#         self.client_key = client_key
#         self.language_pool = language_pool
#         self.base_url = "{proto}://{host}/".format(
#             proto="https" if use_ssl else "http", host=host
#         )
#         self.session = requests.Session()
# 
#     @property
#     def client_ip(self):
#         if not hasattr(self, "_client_ip"):
#             self._client_ip = self.session.get(
#                 "https://api.myip.com", timeout=self.response_timeout
#             ).json()["ip"]
#         return self._client_ip
# 
#     def _check_response(self, response):
#         if response.get("errorId", False) == 11:
#             response[
#                 "errorDescription"
#             ] = "{} Your missing IP address is propably {}.".format(
#                 response["errorDescription"], self.client_ip
#             )
#         if response.get("errorId", False):
#             raise AnticaptchaException(
#                 response["errorId"], response["errorCode"], response["errorDescription"]
#             )
# 
#     def createTask(self, task):
#         request = {
#             "clientKey": self.client_key,
#             "task": task.serialize(),
#             "softId": self.SOFT_ID,
#             "languagePool": self.language_pool,
#         }
#         response = self.session.post(
#             urljoin(self.base_url, self.CREATE_TASK_URL),
#             json=request,
#             timeout=self.response_timeout,
#         ).json()
#         self._check_response(response)
#         return Job(self, response["taskId"])
# 
#     def createTaskSmee(self, task, timeout=MAXIMUM_JOIN_TIME):
#         """
#         Beta method to stream response from smee.io
#         """
#         response = self.session.head(
#             "https://smee.io/new", timeout=self.response_timeout
#         )
#         smee_url = response.headers["Location"]
#         task = task.serialize()
#         request = {
#             "clientKey": self.client_key,
#             "task": task,
#             "softId": self.SOFT_ID,
#             "languagePool": self.language_pool,
#             "callbackUrl": smee_url,
#         }
#         r = self.session.get(
#             url=smee_url,
#             headers={"Accept": "text/event-stream"},
#             stream=True,
#             timeout=(self.response_timeout, timeout),
#         )
#         response = self.session.post(
#             url=urljoin(self.base_url, self.CREATE_TASK_URL),
#             json=request,
#             timeout=self.response_timeout,
#         ).json()
#         self._check_response(response)
#         for line in r.iter_lines():
#             content = line.decode("utf-8")
#             if '"host":"smee.io"' not in content:
#                 continue
#             payload = json.loads(split(content, ":", 1)[1].strip())
#             if "taskId" not in payload["body"] or str(payload["body"]["taskId"]) != str(
#                 response["taskId"]
#             ):
#                 continue
#             r.close()
#             if task["type"] == "CustomCaptchaTask":
#                 payload["body"]["solution"] = payload["body"]["data"][0]
#             job = Job(client=self, task_id=response["taskId"])
#             job._last_result = payload["body"]
#             return job
# 
#     def getTaskResult(self, task_id):
#         request = {"clientKey": self.client_key, "taskId": task_id}
#         response = self.session.post(
#             urljoin(self.base_url, self.TASK_RESULT_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response
# 
#     def getBalance(self):
#         request = {
#             "clientKey": self.client_key,
#             "softId": self.SOFT_ID,
#         }
#         response = self.session.post(
#             urljoin(self.base_url, self.BALANCE_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response["balance"]
# 
#     def getAppStats(self, soft_id, mode):
#         request = {"clientKey": self.client_key, "softId": soft_id, "mode": mode}
#         response = self.session.post(
#             urljoin(self.base_url, self.APP_STAT_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response
# 
#     def reportIncorrectImage(self, task_id):
#         request = {"clientKey": self.client_key, "taskId": task_id}
#         response = self.session.post(
#             urljoin(self.base_url, self.REPORT_IMAGE_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response.get("status", False) != False
# 
#     def reportIncorrectRecaptcha(self, task_id):
#         request = {"clientKey": self.client_key, "taskId": task_id}
#         response = self.session.post(
#             urljoin(self.base_url, self.REPORT_RECAPTCHA_URL), json=request
#         ).json()
#         self._check_response(response)
#         return response["status"] == "success"
# 
# Path: python_anticaptcha/tasks.py
# class FunCaptchaTask(ProxyMixin, FunCaptchaProxylessTask):
#     type = "FunCaptchaTask"


# Path: examples/funcaptcha_request.py
from six.moves.urllib import parse
from os import environ
from random import choice
from python_anticaptcha import AnticaptchaClient, FunCaptchaTask
import requests
import re



api_key = environ["KEY"]
site_key_pattern = 'public_key: "(.+?)",'
url = "https://client-demo.arkoselabs.com/solo-animals"
client = AnticaptchaClient(api_key)
session = requests.Session()


UA = (