File tree Expand file tree Collapse file tree 5 files changed +24
-1
lines changed Expand file tree Collapse file tree 5 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,7 @@ Class defining response from API.
85
85
| ScrapingantInvalidTokenException | The API token is wrong or you have exceeded the API calls request limit
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
+ | ScrapingantSiteNotReachableException | The requested URL is not reachable. Please, check it locally |
88
89
89
90
* * *
90
91
Original file line number Diff line number Diff line change 1
- __version__ = "0.3.3 "
1
+ __version__ = "0.3.4 "
2
2
3
3
from scrapingant_client .client import ScrapingAntClient
4
4
from scrapingant_client .cookie import Cookie
7
7
ScrapingantInvalidTokenException ,
8
8
ScrapingantInvalidInputException ,
9
9
ScrapingantInternalException ,
10
+ ScrapingantSiteNotReachableException ,
10
11
)
11
12
from scrapingant_client .response import Response
12
13
17
18
'ScrapingantInvalidTokenException' ,
18
19
'ScrapingantInvalidInputException' ,
19
20
'ScrapingantInternalException' ,
21
+ 'ScrapingantSiteNotReachableException' ,
20
22
'Response' ,
21
23
]
Original file line number Diff line number Diff line change 11
11
ScrapingantInvalidTokenException ,
12
12
ScrapingantInvalidInputException ,
13
13
ScrapingantInternalException ,
14
+ ScrapingantSiteNotReachableException ,
14
15
)
15
16
from scrapingant_client .response import Response
16
17
from scrapingant_client .utils import base64_encode_string
@@ -54,6 +55,8 @@ def general_request(
54
55
raise ScrapingantInvalidTokenException ()
55
56
elif response .status_code == 422 :
56
57
raise ScrapingantInvalidInputException (response .text )
58
+ elif response .status_code == 404 :
59
+ raise ScrapingantSiteNotReachableException (url )
57
60
elif response .status_code == 500 :
58
61
raise ScrapingantInternalException ()
59
62
json_response = response .json ()
Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ class ScrapingantInvalidInputException(ScrapingantClientException):
13
13
pass
14
14
15
15
16
+ class ScrapingantSiteNotReachableException (ScrapingantClientException ):
17
+ def __init__ (self , url ):
18
+ message = f'The requested URL is not reachable ({ url } )'
19
+ super ().__init__ (message )
20
+
21
+
16
22
class ScrapingantInternalException (ScrapingantClientException ):
17
23
def __init__ (self ):
18
24
message = 'Something went wrong with the server side. Please try later or contact support'
Original file line number Diff line number Diff line change 6
6
ScrapingantInvalidTokenException ,
7
7
ScrapingantInvalidInputException ,
8
8
ScrapingantInternalException ,
9
+ ScrapingantSiteNotReachableException ,
9
10
)
10
11
from scrapingant_client .constants import SCRAPINGANT_API_BASE_URL
11
12
@@ -36,3 +37,13 @@ def test_internal_server_error():
36
37
client = ScrapingAntClient (token = 'some_token' )
37
38
with pytest .raises (ScrapingantInternalException ):
38
39
client .general_request ('bad_url' )
40
+
41
+
42
+ @responses .activate
43
+ def test_not_reachable ():
44
+ responses .add (responses .POST , SCRAPINGANT_API_BASE_URL + '/general' ,
45
+ json = {}, status = 404 )
46
+ client = ScrapingAntClient (token = 'some_token' )
47
+ with pytest .raises (ScrapingantSiteNotReachableException ) as e :
48
+ client .general_request ('example.com' )
49
+ assert 'The requested URL is not reachable (example.com)' in str (e )
You can’t perform that action at this time.
0 commit comments