diff --git a/onshape_to_robot/onshape_api/client.py b/onshape_to_robot/onshape_api/client.py index 353d28b..c241ccd 100644 --- a/onshape_to_robot/onshape_api/client.py +++ b/onshape_to_robot/onshape_api/client.py @@ -14,6 +14,9 @@ import json import hashlib +def escape_slash(s): + return s.replace('/', '%252f') + class Client(): ''' Defines methods for testing the Onshape API. Comes with several methods: @@ -323,18 +326,18 @@ def invoke(): req_headers = { 'Accept': 'application/vnd.onshape.v1+octet-stream' } - return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+partid+'/stl', query={'mode': 'binary', 'units': 'meter', 'configuration': configuration}, headers=req_headers) + return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+escape_slash(partid)+'/stl', query={'mode': 'binary', 'units': 'meter', 'configuration': configuration}, headers=req_headers) return self.cache_get('part_stl', (did, mid, eid, self.hash_partid(partid), configuration), invoke) def part_get_metadata(self, did, mid, eid, partid, configuration = 'default'): def invoke(): - return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+partid+'/metadata', query={'configuration': configuration}) + return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+escape_slash(partid)+'/metadata', query={'configuration': configuration}) return json.loads(self.cache_get('metadata', (did, mid, eid, self.hash_partid(partid), configuration), invoke, True)) def part_mass_properties(self, did, mid, eid, partid, configuration = 'default'): def invoke(): - return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+partid+'/massproperties', query={'configuration': configuration}) + return self._api.request('get', '/api/parts/d/' + did + '/m/' + mid + '/e/' + eid + '/partid/'+escape_slash(partid)+'/massproperties', query={'configuration': configuration}) return json.loads(self.cache_get('massproperties', (did, mid, eid, self.hash_partid(partid), configuration), invoke, True)) diff --git a/onshape_to_robot/onshape_api/onshape.py b/onshape_to_robot/onshape_api/onshape.py index 202d99a..82eb41d 100644 --- a/onshape_to_robot/onshape_api/onshape.py +++ b/onshape_to_robot/onshape_api/onshape.py @@ -221,6 +221,7 @@ def request(self, method, path, query={}, headers={}, body={}, base_url=None): return self.request(method, location.path, query=new_query, headers=headers, base_url=new_base_url) elif not 200 <= res.status_code <= 206: + print(url) print('! ERROR ('+str(res.status_code)+') while using OnShape API') if res.text: print('! '+res.text)