Skip to content

Commit

Permalink
Escaping partids since they can contain slashes (see #46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregwar committed Feb 17, 2021
1 parent 13a78b1 commit 1505136
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
9 changes: 6 additions & 3 deletions onshape_to_robot/onshape_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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))
1 change: 1 addition & 0 deletions onshape_to_robot/onshape_api/onshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1505136

Please sign in to comment.