File tree Expand file tree Collapse file tree 5 files changed +27
-3
lines changed Expand file tree Collapse file tree 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.
8686| ScrapingantInvalidInputException | Invalid value provided. Please, look into error message for more info |
8787| ScrapingantInternalException | Something went wrong with the server side code. Try again later or contact ScrapingAnt support |
8888| 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. |
8990
9091* * *
9192
Original file line number Diff line number Diff line change 1- __version__ = "0.3.4 "
1+ __version__ = "0.3.5 "
22
33from scrapingant_client .client import ScrapingAntClient
44from scrapingant_client .cookie import Cookie
88 ScrapingantInvalidInputException ,
99 ScrapingantInternalException ,
1010 ScrapingantSiteNotReachableException ,
11+ ScrapingantDetectedException ,
1112)
1213from scrapingant_client .response import Response
1314
1920 'ScrapingantInvalidInputException' ,
2021 'ScrapingantInternalException' ,
2122 'ScrapingantSiteNotReachableException' ,
23+ 'ScrapingantDetectedException' ,
2224 'Response' ,
2325]
Original file line number Diff line number Diff line change 1212 ScrapingantInvalidInputException ,
1313 ScrapingantInternalException ,
1414 ScrapingantSiteNotReachableException ,
15+ ScrapingantDetectedException ,
1516)
1617from scrapingant_client .response import Response
1718from scrapingant_client .utils import base64_encode_string
@@ -53,10 +54,12 @@ def general_request(
5354 )
5455 if response .status_code == 403 :
5556 raise ScrapingantInvalidTokenException ()
56- elif response .status_code == 422 :
57- raise ScrapingantInvalidInputException (response .text )
5857 elif response .status_code == 404 :
5958 raise ScrapingantSiteNotReachableException (url )
59+ elif response .status_code == 422 :
60+ raise ScrapingantInvalidInputException (response .text )
61+ elif response .status_code == 423 :
62+ raise ScrapingantDetectedException ()
6063 elif response .status_code == 500 :
6164 raise ScrapingantInternalException ()
6265 json_response = response .json ()
Original file line number Diff line number Diff line change @@ -19,6 +19,13 @@ def __init__(self, url):
1919 super ().__init__ (message )
2020
2121
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+
2229class ScrapingantInternalException (ScrapingantClientException ):
2330 def __init__ (self ):
2431 message = 'Something went wrong with the server side. Please try later or contact support'
Original file line number Diff line number Diff line change 77 ScrapingantInvalidInputException ,
88 ScrapingantInternalException ,
99 ScrapingantSiteNotReachableException ,
10+ ScrapingantDetectedException ,
1011)
1112from scrapingant_client .constants import SCRAPINGANT_API_BASE_URL
1213
@@ -47,3 +48,13 @@ def test_not_reachable():
4748 with pytest .raises (ScrapingantSiteNotReachableException ) as e :
4849 client .general_request ('example.com' )
4950 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