-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8450 from pymedusa/release/release-0.4.2
Release/release 0.4.2
- Loading branch information
Showing
120 changed files
with
11,161 additions
and
14,884 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
from __future__ import absolute_import | ||
from ..exceptions import ( | ||
CaptchaParameter, | ||
CaptchaTimeout, | ||
CaptchaAPIError | ||
) | ||
|
||
try: | ||
from urlparse import urlparse | ||
except ImportError: | ||
from urllib.parse import urlparse | ||
|
||
try: | ||
from python_anticaptcha import ( | ||
AnticaptchaClient, | ||
NoCaptchaTaskProxylessTask, | ||
HCaptchaTaskProxyless, | ||
NoCaptchaTask, | ||
HCaptchaTask, | ||
AnticaptchaException | ||
) | ||
except ImportError: | ||
raise ImportError( | ||
"Please install/upgrade the python module 'python_anticaptcha' via " | ||
"pip install python-anticaptcha or https://github.com/ad-m/python-anticaptcha/" | ||
) | ||
|
||
import sys | ||
|
||
from . import Captcha | ||
|
||
|
||
class captchaSolver(Captcha): | ||
|
||
def __init__(self): | ||
if sys.modules['python_anticaptcha'].__version__ < '0.6': | ||
raise ImportError( | ||
"Please upgrade the python module 'python_anticaptcha' via " | ||
"pip install -U python-anticaptcha or https://github.com/ad-m/python-anticaptcha/" | ||
) | ||
super(captchaSolver, self).__init__('anticaptcha') | ||
|
||
# ------------------------------------------------------------------------------- # | ||
|
||
def parseProxy(self, url, user_agent): | ||
parsed = urlparse(url) | ||
|
||
return dict( | ||
proxy_type=parsed.scheme, | ||
proxy_address=parsed.hostname, | ||
proxy_port=parsed.port, | ||
proxy_login=parsed.username, | ||
proxy_password=parsed.password, | ||
user_agent=user_agent | ||
) | ||
|
||
# ------------------------------------------------------------------------------- # | ||
|
||
def getCaptchaAnswer(self, captchaType, url, siteKey, captchaParams): | ||
if not captchaParams.get('api_key'): | ||
raise CaptchaParameter("anticaptcha: Missing api_key parameter.") | ||
|
||
client = AnticaptchaClient(captchaParams.get('api_key')) | ||
|
||
if captchaParams.get('proxy') and not captchaParams.get('no_proxy'): | ||
captchaMap = { | ||
'reCaptcha': NoCaptchaTask, | ||
'hCaptcha': HCaptchaTask | ||
} | ||
|
||
proxy = self.parseProxy( | ||
captchaParams.get('proxy', {}).get('https'), | ||
captchaParams.get('User-Agent', '') | ||
) | ||
|
||
task = captchaMap[captchaType]( | ||
url, | ||
siteKey, | ||
**proxy | ||
) | ||
else: | ||
captchaMap = { | ||
'reCaptcha': NoCaptchaTaskProxylessTask, | ||
'hCaptcha': HCaptchaTaskProxyless | ||
} | ||
task = captchaMap[captchaType](url, siteKey) | ||
|
||
if not hasattr(client, 'createTaskSmee'): | ||
raise NotImplementedError( | ||
"Please upgrade 'python_anticaptcha' via pip or download it from " | ||
"https://github.com/ad-m/python-anticaptcha/tree/hcaptcha" | ||
) | ||
|
||
job = client.createTaskSmee(task, timeout=180) | ||
|
||
try: | ||
job.join(maximum_time=180) | ||
except (AnticaptchaException) as e: | ||
raise CaptchaTimeout('{}'.format(getattr(e, 'message', e))) | ||
|
||
if 'solution' in job._last_result: | ||
return job.get_solution_response() | ||
else: | ||
raise CaptchaAPIError('Job did not return `solution` key in payload.') | ||
|
||
|
||
# ------------------------------------------------------------------------------- # | ||
|
||
captchaSolver() |
File renamed without changes.
Oops, something went wrong.