@@ -129,6 +129,8 @@ def _init_connection(self) -> requests.Session:
129
129
def _default_headers (self ):
130
130
return {
131
131
'Authorization' : 'Bearer %s' % self .api_key ,
132
+ 'Accept' : 'application/json' ,
133
+ 'Content-Type' : 'application/json' ,
132
134
'X-User-Agent' : f"python-sdk { SDK_VERSION } " ,
133
135
'X-Python-Version' : f"{ python_version_info ()} " ,
134
136
}
@@ -200,20 +202,18 @@ def convert_value(value):
200
202
"/graphql" , "/_gql" )
201
203
202
204
try :
205
+ headers = self ._connection .headers .copy ()
206
+ if files :
207
+ del headers ['Content-Type' ]
208
+ del headers ['Accept' ]
203
209
request = requests .Request ('POST' ,
204
210
endpoint ,
205
- headers = self . _connection . headers ,
211
+ headers = headers ,
206
212
data = data ,
207
213
files = files if files else None )
208
214
209
215
prepped : requests .PreparedRequest = request .prepare ()
210
216
211
- if not files :
212
- prepped .headers .update ({
213
- 'Accept' : 'application/json' ,
214
- 'Content-Type' : 'application/json' ,
215
- })
216
-
217
217
response = self ._connection .send (prepped , timeout = timeout )
218
218
logger .debug ("Response: %s" , response .text )
219
219
except requests .exceptions .Timeout as e :
@@ -419,13 +419,21 @@ def upload_data(self,
419
419
"map" : (None , json .dumps ({"1" : ["variables.file" ]})),
420
420
}
421
421
422
- response = self ._connection .post (
423
- self .endpoint ,
424
- data = request_data ,
425
- files = {
426
- "1" : (filename , content , content_type ) if
427
- (filename and content_type ) else content
428
- })
422
+ files = {
423
+ "1" : (filename , content , content_type ) if
424
+ (filename and content_type ) else content
425
+ }
426
+ headers = self ._connection .headers .copy ()
427
+ headers .pop ("Content-Type" , None )
428
+ request = requests .Request ('POST' ,
429
+ self .endpoint ,
430
+ headers = headers ,
431
+ data = request_data ,
432
+ files = files )
433
+
434
+ prepped : requests .PreparedRequest = request .prepare ()
435
+
436
+ response = self ._connection .send (prepped )
429
437
430
438
if response .status_code == 502 :
431
439
error_502 = '502 Bad Gateway'
@@ -1094,6 +1102,7 @@ def get_feature_schema(self, feature_schema_id):
1094
1102
query_str = """query rootSchemaNodePyApi($rootSchemaNodeWhere: RootSchemaNodeWhere!){
1095
1103
rootSchemaNode(where: $rootSchemaNodeWhere){%s}
1096
1104
}""" % query .results_query_part (Entity .FeatureSchema )
1105
+
1097
1106
res = self .execute (
1098
1107
query_str ,
1099
1108
{'rootSchemaNodeWhere' : {
@@ -1204,10 +1213,7 @@ def delete_unused_feature_schema(self, feature_schema_id: str) -> None:
1204
1213
1205
1214
endpoint = self .rest_endpoint + "/feature-schemas/" + urllib .parse .quote (
1206
1215
feature_schema_id )
1207
- response = self ._connection .delete (
1208
- endpoint ,
1209
- headers = self .headers ,
1210
- )
1216
+ response = self ._connection .delete (endpoint ,)
1211
1217
1212
1218
if response .status_code != requests .codes .no_content :
1213
1219
raise labelbox .exceptions .LabelboxError (
@@ -1224,10 +1230,7 @@ def delete_unused_ontology(self, ontology_id: str) -> None:
1224
1230
"""
1225
1231
endpoint = self .rest_endpoint + "/ontologies/" + urllib .parse .quote (
1226
1232
ontology_id )
1227
- response = self ._connection .delete (
1228
- endpoint ,
1229
- headers = self .headers ,
1230
- )
1233
+ response = self ._connection .delete (endpoint ,)
1231
1234
1232
1235
if response .status_code != requests .codes .no_content :
1233
1236
raise labelbox .exceptions .LabelboxError (
@@ -1251,7 +1254,6 @@ def update_feature_schema_title(self, feature_schema_id: str,
1251
1254
feature_schema_id ) + '/definition'
1252
1255
response = self ._connection .patch (
1253
1256
endpoint ,
1254
- headers = self .headers ,
1255
1257
json = {"title" : title },
1256
1258
)
1257
1259
@@ -1284,7 +1286,6 @@ def upsert_feature_schema(self, feature_schema: Dict) -> FeatureSchema:
1284
1286
feature_schema_id )
1285
1287
response = self ._connection .put (
1286
1288
endpoint ,
1287
- headers = self .headers ,
1288
1289
json = {"normalized" : json .dumps (feature_schema )},
1289
1290
)
1290
1291
@@ -1314,7 +1315,6 @@ def insert_feature_schema_into_ontology(self, feature_schema_id: str,
1314
1315
feature_schema_id )
1315
1316
response = self ._connection .post (
1316
1317
endpoint ,
1317
- headers = self .headers ,
1318
1318
json = {"position" : position },
1319
1319
)
1320
1320
if response .status_code != requests .codes .created :
@@ -1339,7 +1339,6 @@ def get_unused_ontologies(self, after: str = None) -> List[str]:
1339
1339
endpoint = self .rest_endpoint + "/ontologies/unused"
1340
1340
response = self ._connection .get (
1341
1341
endpoint ,
1342
- headers = self .headers ,
1343
1342
json = {"after" : after },
1344
1343
)
1345
1344
@@ -1367,7 +1366,6 @@ def get_unused_feature_schemas(self, after: str = None) -> List[str]:
1367
1366
endpoint = self .rest_endpoint + "/feature-schemas/unused"
1368
1367
response = self ._connection .get (
1369
1368
endpoint ,
1370
- headers = self .headers ,
1371
1369
json = {"after" : after },
1372
1370
)
1373
1371
@@ -1890,10 +1888,7 @@ def is_feature_schema_archived(self, ontology_id: str,
1890
1888
1891
1889
ontology_endpoint = self .rest_endpoint + "/ontologies/" + urllib .parse .quote (
1892
1890
ontology_id )
1893
- response = self ._connection .get (
1894
- ontology_endpoint ,
1895
- headers = self .headers ,
1896
- )
1891
+ response = self ._connection .get (ontology_endpoint ,)
1897
1892
1898
1893
if response .status_code == requests .codes .ok :
1899
1894
feature_schema_nodes = response .json ()['featureSchemaNodes' ]
@@ -1969,10 +1964,7 @@ def delete_feature_schema_from_ontology(
1969
1964
ontology_endpoint = self .rest_endpoint + "/ontologies/" + urllib .parse .quote (
1970
1965
ontology_id ) + "/feature-schemas/" + urllib .parse .quote (
1971
1966
feature_schema_id )
1972
- response = self ._connection .delete (
1973
- ontology_endpoint ,
1974
- headers = self .headers ,
1975
- )
1967
+ response = self ._connection .delete (ontology_endpoint ,)
1976
1968
1977
1969
if response .status_code == requests .codes .ok :
1978
1970
response_json = response .json ()
@@ -2006,10 +1998,7 @@ def unarchive_feature_schema_node(self, ontology_id: str,
2006
1998
ontology_endpoint = self .rest_endpoint + "/ontologies/" + urllib .parse .quote (
2007
1999
ontology_id ) + '/feature-schemas/' + urllib .parse .quote (
2008
2000
root_feature_schema_id ) + '/unarchive'
2009
- response = self ._connection .patch (
2010
- ontology_endpoint ,
2011
- headers = self .headers ,
2012
- )
2001
+ response = self ._connection .patch (ontology_endpoint ,)
2013
2002
if response .status_code == requests .codes .ok :
2014
2003
if not bool (response .json ()['unarchived' ]):
2015
2004
raise labelbox .exceptions .LabelboxError (
0 commit comments