@@ -18,6 +18,14 @@ class UploadError(RoboflowError):
18
18
pass
19
19
20
20
21
+ class ImageUploadError (RoboflowError ):
22
+ def __init__ (self , message , status_code = None ):
23
+ self .message = message
24
+ self .status_code = status_code
25
+ self .retries = 0
26
+ super ().__init__ (self .message )
27
+
28
+
21
29
def get_workspace (api_key , workspace_url ):
22
30
url = f"{ API_URL } /{ workspace_url } ?api_key={ api_key } "
23
31
response = requests .get (url )
@@ -78,24 +86,29 @@ def upload_image(
78
86
79
87
else :
80
88
# Hosted image upload url
81
-
82
89
upload_url = _hosted_upload_url (api_key , project_url , image_path , split , coalesced_batch_name , tag_names )
90
+
83
91
# Get response
84
92
response = requests .post (upload_url , timeout = (300 , 300 ))
93
+
85
94
responsejson = None
86
95
try :
87
96
responsejson = response .json ()
88
97
except Exception :
89
98
pass
99
+
90
100
if response .status_code != 200 :
91
101
if responsejson :
92
- raise UploadError ( f"Bad response: { response .status_code } : { responsejson } " )
102
+ raise ImageUploadError ( responsejson , status_code = response .status_code )
93
103
else :
94
- raise UploadError (f"Bad response: { response } " )
104
+ raise ImageUploadError (response )
105
+
95
106
if not responsejson : # fail fast
96
- raise UploadError (f"upload image { image_path } 200 OK, unexpected response: { response } " )
107
+ raise ImageUploadError (response , status_code = response .status_code )
108
+
97
109
if not (responsejson .get ("success" ) or responsejson .get ("duplicate" )):
98
- raise UploadError (f"Server rejected image: { responsejson } " )
110
+ raise ImageUploadError (responsejson )
111
+
99
112
return responsejson
100
113
101
114
0 commit comments