File tree 5 files changed +27
-3
lines changed
5 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -86,6 +86,7 @@ Class defining response from API.
86
86
| ScrapingantInvalidInputException | Invalid value provided. Please, look into error message for more info |
87
87
| ScrapingantInternalException | Something went wrong with the server side code. Try again later or contact ScrapingAnt support |
88
88
| ScrapingantSiteNotReachableException | The requested URL is not reachable. Please, check it locally |
89
+ | ScrapingantDetectedException | The anti-bot detection system has detected the request. Please, retry or change the request settings. |
89
90
90
91
* * *
91
92
Original file line number Diff line number Diff line change 1
- __version__ = "0.3.4 "
1
+ __version__ = "0.3.5 "
2
2
3
3
from scrapingant_client .client import ScrapingAntClient
4
4
from scrapingant_client .cookie import Cookie
8
8
ScrapingantInvalidInputException ,
9
9
ScrapingantInternalException ,
10
10
ScrapingantSiteNotReachableException ,
11
+ ScrapingantDetectedException ,
11
12
)
12
13
from scrapingant_client .response import Response
13
14
19
20
'ScrapingantInvalidInputException' ,
20
21
'ScrapingantInternalException' ,
21
22
'ScrapingantSiteNotReachableException' ,
23
+ 'ScrapingantDetectedException' ,
22
24
'Response' ,
23
25
]
Original file line number Diff line number Diff line change 12
12
ScrapingantInvalidInputException ,
13
13
ScrapingantInternalException ,
14
14
ScrapingantSiteNotReachableException ,
15
+ ScrapingantDetectedException ,
15
16
)
16
17
from scrapingant_client .response import Response
17
18
from scrapingant_client .utils import base64_encode_string
@@ -53,10 +54,12 @@ def general_request(
53
54
)
54
55
if response .status_code == 403 :
55
56
raise ScrapingantInvalidTokenException ()
56
- elif response .status_code == 422 :
57
- raise ScrapingantInvalidInputException (response .text )
58
57
elif response .status_code == 404 :
59
58
raise ScrapingantSiteNotReachableException (url )
59
+ elif response .status_code == 422 :
60
+ raise ScrapingantInvalidInputException (response .text )
61
+ elif response .status_code == 423 :
62
+ raise ScrapingantDetectedException ()
60
63
elif response .status_code == 500 :
61
64
raise ScrapingantInternalException ()
62
65
json_response = response .json ()
Original file line number Diff line number Diff line change @@ -19,6 +19,13 @@ def __init__(self, url):
19
19
super ().__init__ (message )
20
20
21
21
22
+ class ScrapingantDetectedException (ScrapingantClientException ):
23
+ def __init__ (self ):
24
+ message = 'The anti-bot detection system has detected the request. ' \
25
+ 'Please, retry or change the request settings.'
26
+ super ().__init__ (message )
27
+
28
+
22
29
class ScrapingantInternalException (ScrapingantClientException ):
23
30
def __init__ (self ):
24
31
message = 'Something went wrong with the server side. Please try later or contact support'
Original file line number Diff line number Diff line change 7
7
ScrapingantInvalidInputException ,
8
8
ScrapingantInternalException ,
9
9
ScrapingantSiteNotReachableException ,
10
+ ScrapingantDetectedException ,
10
11
)
11
12
from scrapingant_client .constants import SCRAPINGANT_API_BASE_URL
12
13
@@ -47,3 +48,13 @@ def test_not_reachable():
47
48
with pytest .raises (ScrapingantSiteNotReachableException ) as e :
48
49
client .general_request ('example.com' )
49
50
assert 'The requested URL is not reachable (example.com)' in str (e )
51
+
52
+
53
+ @responses .activate
54
+ def test_detected ():
55
+ responses .add (responses .POST , SCRAPINGANT_API_BASE_URL + '/general' ,
56
+ json = {}, status = 423 )
57
+ client = ScrapingAntClient (token = 'some_token' )
58
+ with pytest .raises (ScrapingantDetectedException ) as e :
59
+ client .general_request ('example.com' )
60
+ assert 'The anti-bot detection system has detected the request' in str (e )
You can’t perform that action at this time.
0 commit comments