
    ^j                         d dl mZ d dlZd dlZ	 d dlZddlmZmZm	Z	m
Z
mZmZ ddlmZ  G d d	e      Z e        y# e$ r	  ed      w xY w)
    )absolute_importNzlPlease install the python module 'polling' via pip or download it from https://github.com/justiniso/polling/   )CaptchaExceptionCaptchaServiceUnavailableCaptchaAPIErrorCaptchaTimeoutCaptchaParameterCaptchaBadJobID   )Captchac                   @     e Zd Z fdZed        Zd Zd Zd Z xZ	S )captchaSolverc                     t         t        |   d       d| _        d| _        t        j                         | _        ddd| _        y )N9kwzhttps://www.9kw.eu/index.cgi   recaptchav2hcaptcha)	reCaptchahCaptcha)	superr   __init__host
maxtimeoutrequestsSessionsessioncaptchaType)self	__class__s    S/var/www/lego-monitor/venv/lib/python3.12/site-packages/cloudscraper/captcha/9kw.pyr   zcaptchaSolver.__init__   s@    mT+E22	'')&"
    c           	      V   | j                   dv rt        d| j                          i ddddddd	d
dddddddddddddddddddddd d!d"d#d$i d%dd&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEi dFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXdYdZd[d\d]d^d_d`dadbdcdddedfdgdhdidjdk}| j                  j                  dl      r`| j	                         j                  dm      r@t        |j                  t        | j	                         j                  dm                        y t        t        j                  dn| j                        j                         j                  dodp            }|rt        |j                  |            y )qN)i  i  z9kw: Server Side Error r   zNo API Key available.r   zNo API key found.   zNo active API key found.   z+API Key has been disabled by the operator.    zNo user found.   zNo data found.   zFound No ID.   zfound No captcha.	   zNo image found.
   zImage size not allowed.   zcredit is not sufficient.   zwhat was done.   zNo answer contain.   zCaptcha already been answered.   zCaptcha to quickly filed.   zJD check active.   zUnknown problem.      zIncorrect answer.   z'Do not timely filed (Incorrect UserID).   zLink not allowed.   zProhibited submit.   zEntering prohibited.   zToo little credit.   zNo entry found.   zNo Conditions accepted.   z%No coupon code found in the database.   zAlready unused voucher code.   zmaxTimeout under 60 seconds.   zUser not found.   z)An account is not yet 24 hours in system.    z)An account does not have the full rights.!   zPlugin needed a update."   zNo HTTPS allowed.#   zNo HTTP allowed.$   zSource not allowed.%   zTransfer denied.&   zIncorrect answer without space'   zIncorrect answer with space(   z&Incorrect answer with not only numbers)   z'Incorrect answer with not only A-Z, a-z*   z,Incorrect answer with not only 0-9, A-Z, a-z+   z'Incorrect answer with not only [0-9,- ],   z-Incorrect answer with not only [0-9A-Za-z,- ]-   z*Incorrect answer with not only coordinates.   z3Incorrect answer with not only multiple coordinates/   z#Incorrect answer with not only data0   z,Incorrect answer with not only rotate number1   z#Incorrect answer with not only text2   z1Incorrect answer with not only text and too short3   z&Incorrect answer with not enough charsz$Incorrect answer with too many charsz"Incorrect answer without no or yeszAssignment was not found.)4   5   6   {errorz^00(?P<error_code>\d+)
error_coder   )status_coder   text
startswithjsongetr   intresearch	groupdict)responseerror_codesrY   s      r    checkErrorStatuszcaptchaSolver.checkErrorStatus(   s   :-+)(*>*>)?@ 7
&7
"7
 )7
 <	7

 7
 7
 ~7
 "7
  7
 )7
 +7
  7
 $7
 07
 +7
  "!7
" "#7
$ %7
& #'7
( 9)7
* #+7
, $-7
. &/7
0 $17
2 !37
4 )57
6 777
8 .97
: .;7
< !=7
> ;?7
@ ;A7
B )C7
D #E7
F "G7
H %I7
J "K7
L 0M7
N -O7
P 8Q7
R 9S7
T >U7
V 9W7
X ?Y7
Z <[7
\ E]7
^ 5_7
` >a7
b 5c7
d Ce7
f 8g7
h 74+m7
r ==##C(}}""7+%kooc(--/:M:Mg:V6W&XYY , RYY'@(--PZZ\``amopqrJ%kooj&ABB r!   c                      st        d       fd}t        j                   fd|d j                  dz         }|r|j	                         j                  d      S t        d      )Nz)9kw: Error bad job id to request against.c                     | j                   r$| j                         j                  d      dk7  r| S j                  |        y )NanswerzNO DATA)okr]   r^   re   rc   r   s    r    _checkRequestz/captchaSolver.requestJob.<locals>._checkRequestx   s8    {{x}}228<	I!!(+r!   c            	      r    j                   j                  j                  j                  d ddd      S )Nusercaptchacorrectdatar   )apikeyactionidinfor]   )params)r   r^   r   api_key)jobIDr   s   r    <lambda>z*captchaSolver.requestJob.<locals>.<lambda>   s:    DLL$$		"ll6 % 	 r!   r*   check_successsteptimeoutrh   z9kw: Error failed to solve.)r
   pollingpollr   r]   r^   r   )r   rt   rk   rc   s   ``  r    
requestJobzcaptchaSolver.requestJobr   sl    !; 	 <<	 (__r)
  ==?&&x00 !>??r!   c                       fd}t        j                   fd|d j                  dz         }|r|j                         j	                  d      S t        d      )Nc                     | j                   r<| j                  j                  d      r!| j                         j	                  d      r| S j                  |        y )NrW   	captchaid)ri   r[   r\   r]   r^   re   rj   s    r    rk   z1captchaSolver.requestSolve.<locals>._checkRequest   sE    {{x}}77<ATATU`Aa!!(+r!   c                      j                   j                  j                  j                  ddj                      j
                  ddd      S )Nusercaptchauploadr   )rn   ro   interactivezfile-upload-01	oldsourcepageurlr   r]   F)dataallow_redirects)r   postr   rs   r   r   )r   r   siteKeyurls   r    ru   z,captchaSolver.requestSolve.<locals>.<lambda>   sW    DLL%%		"ll1#$&-!%!1!1+!>""&//	 !& &  r!   r%   r*   rv   r   z(9kw: Error no valid job id was returned.)rz   r{   r   r]   r^   r
   )r   r   r   r   rk   rc   s   ````  r    requestSolvezcaptchaSolver.requestSolve   sY    	 << (__r)#
( ==?&&{33!"LMMr!   c                    d }|j                  d      st        d      |j                  d      | _        |j                  d      r|j                  d      | _        |j                  d      r |j                  d      | j                  _        || j                  vrt        d| d      	 | j                  |||      }| j                  |      S # t        j                  $ r t        d| d	      w xY w)
Nrs   z9kw: Missing api_key parameter.r   proxyproxiesz9kw: z# is not supported by this provider.z/9kw: solve took to long to execute 'captchaid' z, aborting.)r^   r	   rs   r   r   r   r   r   r   r|   rz   TimeoutExceptionr   )r   r   r   r   captchaParamsrt   s         r    getCaptchaAnswerzcaptchaSolver.getCaptchaAnswer   s      +"#DEE$((3\*+//=DOW%#0#4#4Y#?DLL d..."U;-7Z#[\\	%%k3@E??5))'' 	 A%T 	s   +#C #C2)
__name__
__module____qualname__r   staticmethodre   r|   r   r   __classcell__)r   s   @r    r   r      s4    
 EC ECR!@J NFr!   r   )
__future__r   r`   r   rz   ImportError
exceptionsr   r   r   r   r	   r
    r   r    r!   r    <module>r      s_    & 	   wG wx ]  
	0 s	   = A