onshape-public / onshape-clients Goto Github PK
View Code? Open in Web Editor NEWAll Onshape clients for interacting with the Onshape API.
License: MIT License
All Onshape clients for interacting with the Onshape API.
License: MIT License
As discussed, request for export DWG/DXF python endpoint
After following the steps outlined for building the client code, most of the files match, but there are a few files which show minor differences:
api_applications.go, api_assemblies.go, api_blob_elements.go, api_documents.go, and api_parts.go adds some extra 200 checking in the Execute().
You can see the changes in toebes/go-client/commit/628eb92629a55bbdaf678bb385f00582ea8ffeb5
As the title states, when I am trying to download an obj file from the /api/documents/d/did/externaldata/fid endpoint, I get a "UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position 47: invalid continuation byte" error.
My current fix for this is to literally just comment out the two lines of code that decode the response but I was wondering if this is an actual issue or if I'm doing something wrong.
The function that I've written, for reference:
def download_obj(resultExternalID,did,filename,access_key, secret_key):
# Instantiate the client
base = 'https://cad.onshape.com'
client = Client(configuration={"base_url": base,
"access_key": access_key,
"secret_key": secret_key})
# Create URL
fixed_url = '/api/documents/d/did/externaldata/fid'
# did = '440f9b2f28d38a7527ddb35d'
# resultExternalID = '6188baeead512e1ebd7f2c5b'
fixed_url = fixed_url.replace('fid', resultExternalID)
fixed_url = fixed_url.replace('did', did)
# Process request
method = 'GET'
params = {}
payload = {}
headers = {'Accept': 'application/vnd.onshape.v1+json; charset=UTF-8;qs=0.1',
'Content-Type': 'application/json'}
response = client.api_client.request(method, url=base + fixed_url, query_params=params, headers=headers, body=payload)
# Write request to file
with open(filename + '.zip', "wb") as handle:
handle.write(response.data)
All the (GET) calls in the AssembliesApi
[1] return None.
But I am expecting the calls to return some content, as I can see the json
content in the API explorer.
If I specify _preload_content=False
as parameter, then I obtain the HTTPResponse
which contain the unparsed JSON response. So, it seems to me that it is missing the parsing part.
I'm calling
eval_feature_script with the part studio ids, configuration, bt_feature_script_eval_call, and _preload_content=False
In my configuration I've added values for access_key and secret_key.
However I get this error:
File "/home/user/code/urdf_gen/onshape/onshape-clients/python/onshape_client/api/part_studios_api.py", line 555, in eval_feature_script
(data) = self.eval_feature_script_with_http_info(did, wvm, wvmid, eid, **kwargs) # noqa: E501
File "/home/user/code/urdf_gen/onshape/onshape-clients/python/onshape_client/api/part_studios_api.py", line 660, in eval_feature_script_with_http_info
collection_formats=collection_formats)
File "/home/user/code/urdf_gen/onshape/onshape-clients/python/onshape_client/api_client.py", line 337, in call_api
_preload_content, _request_timeout)
File "/home/user/code/urdf_gen/onshape/onshape-clients/python/onshape_client/api_client.py", line 142, in __call_api
query_params = self.sanitize_for_serialization(query_params)
File "/home/user/code/urdf_gen/onshape/onshape-clients/python/onshape_client/api_client.py", line 206, in sanitize_for_serialization
for sub_obj in obj]
File "/home/user/code/urdf_gen/onshape/onshape-clients/python/onshape_client/api_client.py", line 206, in <listcomp>
for sub_obj in obj]
File "/home/user/code/urdf_gen/onshape/onshape-clients/python/onshape_client/api_client.py", line 209, in sanitize_for_serialization
for sub_obj in obj)
File "/home/user/code/urdf_gen/onshape/onshape-clients/python/onshape_client/api_client.py", line 209, in <genexpr>
for sub_obj in obj)
File "/home/user/code/urdf_gen/onshape/onshape-clients/python/onshape_client/api_client.py", line 222, in sanitize_for_serialization
for attr, _ in six.iteritems(obj.openapi_types)
AttributeError: 'Configuration' object has no attribute 'openapi_types'
When in the python api one tries to make an api call that uses part_id for example as the following:
meta_data = client.metadata_api.get_wmvep_metadata(self.docId, 'm', self.mversion, self.eleId, self.partId, _preload_content=False, configuration=self.configuration_string)
this works as long as the self.partId
does not have a + in it. So in my case the partId is: "J+D" which results in an url of:
'https://cad.onshape.com/api/metadata/d/9d2fc0446a58886a95a1c94d/m/d95ab1f3bb752522c9159dde/e/fc4e9644495e71e2ce43824f/p/J%2BD'
which fails to retrieve the correct part.
I'm trying to instantiate a ConfiguredOnshapeElement
from a URL according to these instructions, but I'm getting an error while doing so.
I have onshape-client==0.0.25
installed, and ~/.onshape_client_config.yaml
set as follows:
prod-api_keys:
baseUrl: 'https://cad.onshape.com'
access_key: (my access key)
secret_key: (my secret key)
prod-oauth:
baseUrl: 'https://cad.onshape.com'
default_stack: prod-api_keys
I try running the following code:
>>> from onshape_client.client import Client
>>> from onshape_client.onshape_url import ConfiguredOnshapeElement
>>> url = "https://cad.onshape.com/documents/cca81d10f239db0db9481e6f/v/aaa25d18038e06f0b2964e2d/e/69c9eedda86512966b20bc90"
>>> element = ConfiguredOnshapeElement(url)
This results in the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/oliver/.local/lib/python3.6/site-packages/onshape_client/onshape_url.py", line 73, in __init__
self._raw_configuration_params = self._get_raw_configuration_params()
File "/home/oliver/.local/lib/python3.6/site-packages/onshape_client/onshape_url.py", line 156, in _get_raw_configuration_params
_preload_content=False)
File "/home/oliver/.local/lib/python3.6/site-packages/onshape_client/api/elements_api.py", line 541, in get_configuration3
(data) = self.get_configuration3_with_http_info(did, wvm, wvmid, eid, **kwargs) # noqa: E501
File "/home/oliver/.local/lib/python3.6/site-packages/onshape_client/api/elements_api.py", line 636, in get_configuration3_with_http_info
collection_formats=collection_formats)
File "/home/oliver/.local/lib/python3.6/site-packages/onshape_client/api_client.py", line 337, in call_api
_preload_content, _request_timeout)
File "/home/oliver/.local/lib/python3.6/site-packages/onshape_client/api_client.py", line 168, in __call_api
_request_timeout=_request_timeout)
File "/home/oliver/.local/lib/python3.6/site-packages/onshape_client/api_client.py", line 358, in request
headers=headers)
File "/home/oliver/.local/lib/python3.6/site-packages/onshape_client/rest.py", line 292, in GET
query_params=query_params)
File "/home/oliver/.local/lib/python3.6/site-packages/onshape_client/rest.py", line 238, in request
retries=urllib3.Retry(total=False, redirect=False, raise_on_redirect=False))
File "/home/oliver/.local/lib/python3.6/site-packages/urllib3/request.py", line 68, in request
**urlopen_kw)
File "/home/oliver/.local/lib/python3.6/site-packages/urllib3/request.py", line 89, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "/home/oliver/.local/lib/python3.6/site-packages/urllib3/poolmanager.py", line 315, in urlopen
conn = self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
File "/home/oliver/.local/lib/python3.6/site-packages/urllib3/poolmanager.py", line 222, in connection_from_host
raise LocationValueError("No host specified.")
urllib3.exceptions.LocationValueError: No host specified.
Should I be changing the way that I instantiate the Client
?
I get a None response after running the code below.
The workspace is not empty.
I tested the same api call in my browser and it works as expected.
Code:
dummy.txt
Hello, I was reading through the endpointsApi.ts
module and I saw we get the list of endpoints by calling an endpoint that's called https://cad.onshape.com/api/endpoints
- but when I tried this out in Postman, I received a HTTP 404 response.
Here is the line of code that makes me suspicious:
https://github.com/onshape-public/onshape-clients/blob/4f613cc4025a90e11493e2b79560afe9762e1686/typescript-node/api/endpointsApi.ts#LL81C25-L81C25
Perhaps this endpoint is no longer supported in the Onshape API? Or maybe I'm just missing something?
Looks like the example creds file regressed a bit. And tests aren't the easiest to run.
Now, I get this : KeyError: “Your creds file is not constructed as expected. The key: ‘onshape_client_test’ was expected and not found.”
Couple of things I noticed, the sample .onshape_client_config.yaml had dummy content prod_oauth, looking at the code, was using that information to authenticate via oauth instead of the API keys ( I could be wrong).
7:11
Secondly the Endpoint (above code snippet ) is using “auth”: [“OAuth2"], I am using the API keys. Could this be the issue? (edited)
7:11
FWIW, I am able to run the samples in the apikey repository without any issues.
copyelements api call works to create a new elements in a new tab in the UI but doesn't return json text.
Apparently STEP and ShadedViews file downloads are not working.
i want to use the api draw a skecth and extrude it,but the examples does not offer it,it's hard to know how to handle it,if it;s possible,cloud you please offer some more examples
I was trying to export the STL of a single part (as identified by an element_id
and part_id
) but while the call exists in API Explorer, it does not exist in the Python parts_api
counterpart.
There exist a corresponding API in PartStudios, but unfortunately it returns the STL for the whole element, while I need the single components.
Is it possible to add this function to the exported APIs?
(The endpoint I am looking for is /parts/d/:did/[wvm]/:wvm/e/:eid/partid/:partid/stl
)
Shouldn't this api call return a dictionary similar to the Get Translation Status call in the API Explorer?
For example https://github.com/onshape-public/onshape-clients/blob/master/typescript-node/api/accountsApi.ts#L13
has the line
import localVarRequest = require('request');
Which seems to refer to https://www.npmjs.com/package/request
However documentation on that page that request was deprecated over three years ago.
When calling the Python Assembly.get_features
function, the server returns
HTTP response body: {
"moreInfoUrl" : "",
"message" : "Request not acceptable.",
"status" : 406,
"code" : 0
}
Comparing the API Explorer and the Python implementation I found a different definition for the header accept
key:
The API explorer gives:
application/vnd.onshape.v1+json
while Python: application/vnd.onshape.v2+json;charset=UTF-8;qs=0.2
Note that v1
vs v2
. Changing the Python to match the API explorer I can at least make the call (still need to _preload_content=False
to avoid exceptions while parsing
Hello,
I am currently trying to build an integration from Onshape into my PLM system. The first part of this (for my use case) is seeing how to listen for a webhook event from Onshape, whenever a new release package gets created for one of my assemblies.
Is there any docs/examples on how to potentially do this through the BTReleasePackageWorkflowChangeParams
? Thanks in advance @eak24
Originally tests in Go were designed to create a private Onshape document but CI infrastructure uses a free account, which only allows access to public documents.
We need to handle this situation: if the creation of a private document fails with 409 Responses we should try to create a public one.
See original failure here
Not sure if this is the right place for this bug report but if I do:
pip install --upgrade onshape-client==0.0.37
it does not install correctly and a simple "import onshape_client" does not work.
Python 3.6.6 (default, Jul 19 2018, 14:25:17)
[GCC 8.1.1 20180712 (Red Hat 8.1.1-5)] on linux
Type "help", "copyright", "credits" or "license" for more informationimport onshape_client
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'onshape_client'
Doing pip install --upgrade onshape-client==0.0.35
does work.
Version 37 seems to install to .../env3/lib/python3.6/site-packages/python/ rather than
.../env3/lib/python3.6/site-packages/onshape_client
Those are the transformation matrix that I apply for each position:
top
[[1. 0. 0.]
[0. 1. 0.]
[0. 0. 1.]]
bottom
[[ 1.0000000e+00 0.0000000e+00 0.0000000e+00]
[ 0.0000000e+00 -1.0000000e+00 -1.2246468e-16]
[ 0.0000000e+00 1.2246468e-16 -1.0000000e+00]]
front
[[ 1.000000e+00 0.000000e+00 0.000000e+00]
[ 0.000000e+00 6.123234e-17 1.000000e+00]
[ 0.000000e+00 -1.000000e+00 6.123234e-17]]
back
[[ 1.000000e+00 0.000000e+00 0.000000e+00]
[ 0.000000e+00 6.123234e-17 -1.000000e+00]
[ 0.000000e+00 1.000000e+00 6.123234e-17]]
left
[[ 6.123234e-17 0.000000e+00 1.000000e+00]
[ 0.000000e+00 1.000000e+00 0.000000e+00]
[-1.000000e+00 0.000000e+00 6.123234e-17]]
right
[[ 6.123234e-17 0.000000e+00 -1.000000e+00]
[ 0.000000e+00 1.000000e+00 0.000000e+00]
[ 1.000000e+00 0.000000e+00 6.123234e-17]]
iso
[[ 0.5 -0.5 0.70710678]
[ 0.85355339 0.14644661 -0.5 ]
[ 0.14644661 0.85355339 0.5 ]]
So, if I want to apply a translation, what I do first is to multiply also the translation matrix for the matrix of the bounding box in the form:
high_x low_x
high_y low_y
high_z low_z
Then I substrate high minus low of echa point, and I divide also each point by -2 to get the translation of x, y, and z. and aI add this column to the view matrix.
This works for almost all cases, but there are cases when this doesn't work and the image that i get is too small for one or all perspectives.
What I've seen is that for a large image with the top of the bounding box in the center of the coordinate axe I take very small pictures in all positions. And for images with one of the dimensions of the bounding box too much larger than the other two, I also get the image very small for two of the perspectives...
My question is fi you know any function to apply to the column of translation of the transformation matrix to emulate the zoom in of the camera in those cases keeping the image framed
I’ve been attempting to use the Onshape GO APIs and am slowly coming to the conclusion that it would be nicer if they utilized a different strategy for GO. Basically there are two issues to consider here that I’ve described in detail below:
It isn’t obvious why there is both a client
and a context
object for accessing the APIs. It basically means that every routine needs to have two pieces of information passed to them if they are to access the APIs. Now it certainly is possible that someone could just create them as global variables, but that of course is not good programming practice. For example, the typical application will do something like:
config := onshape.NewConfiguration()
config.Debug = onshapeDebug
client := onshape.NewAPIClient(config)
if apiSecretKey == "" {
apiSecretKey = os.Getenv("ONSHAPE_API_SECRET_KEY")
}
if apiAccessKey == "" {
apiAccessKey = os.Getenv("ONSHAPE_API_ACCESS_KEY")
}
if onshapeDebug {
fmt.Printf("Keys: Secret=%v Access=%v\n", apiSecretKey, apiAccessKey)
}
ctx := context.WithValue(context.Background(), onshape.ContextAPIKeys, onshape.APIKeys{SecretKey: apiSecretKey, AccessKey: apiAccessKey})
Once that has been done, every call needs to be referenced from the client
and the first parameter passed is the context
. If you look into the client
and context
structures, you find that the context
is the typical GO context (https://golang.org/pkg/context/) which allows for storing all sorts of useful data. On the other hand, the client
object is not much more than a pointer to all of the function groups and the config object. Examining the information stored in the config object you find some HTTP header/agent information and the Debug
flag, all of things that could be stored in the context
object using the WithValue()
method.
Furthermore, having the client
object provides for some unwieldy access to the APIs. Not only does a developer have to look up the name of the API, they also have to look up the category to call it. Currently there are 193 API entries in 26 different classes (three of the classes have only one API entry and three more only have two) and there are no conflicts on names for any of the APIs. So instead of a developer calling:
docInfo, rawResp, err := client.DocumentsApi.CreateDocument(ctx).BTDocumentParams(*docParams).Execute()
it would make much more sense for them to call:
docInfo, err := CreateDocument(ctx).BTDocumentParams(*docParams).Execute()`
The current stubs require a lot of overhead on the part of the caller. In addition to juggling the parameters into place, the caller has to handle quite a few error cases. Here’s an example of a typical call to just get the metadata for a documemt:
// Get the Metadata for the document. This returns the list of lower level tabs in the document
// fmt.Printf("Calling: /api/metadata/d/%v/w/%v/e\n", *did, *wvid)
// Declare the variables that we will be filling in during the loop.
var MetadataNodes onshape.BTMetadataInfo
var rawResp *http.Response
var err error
// Arbitrarily we aren’t going to try more than 50 times. In the worst case we will be delaying 2.5 seconds between calls
for delay := 0; delay < 50; delay++ {
MetadataNodes, rawResp, err = client.MetadataApi.GetWMVEsMetadata(ctx, *did, "w", *wvid).Depth("5").Execute()
// If we are rate limited, implement a backoff strategy
// We only find out that it is a backoff if the error string has a 429 followed by a single space.
if err == nil || err.Error() != "429 " {
// Not a rate limit so we can stop retrying
break
}
// Rate limited, implement a progressive backoff adding 50ms each time through the loop.
fmt.Printf(".......Rate Limited.. Sleeping\n")
time.Sleep(time.Duration(delay*50) * time.Millisecond)
}
// Check to see if we have any actual errors returned
if err != nil {
// Propagate the error to the caller
return err
// Check to see if we had a HTTP response code of 300 or higher which indicates a failure
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
// but which wasn’t returned as an error code from the lower level API
} else if rawResp != nil && rawResp.StatusCode >= 300 {
// The API actually failed, so format an error code to propagate up
err = fmt.Errorf("err: Response status: %v", rawResp)
return err
}
What would make a lot more sense for general usage would be a call
MetadataNodes, err = GetWMVEsMetadata(ctx, *did, "w", *wvid).Depth("5").Execute()
if err != nil {
return err
}
In this case, the stub should handle the 429 and the 300 errors returning only an error
and not the _nethttp.Response
code. It would also ensure uniform processing of any back-off strategy to ensure optimal use of the Onshape APIs. I’m happy to create a stub that encapsulates all of this, but it feels odd to build a shim layer on top of another shim layer (which is actually layered at least one more level deep).
a call to part_studios_api.get_body_details2 raises the exception:
Invalid value for type (plane), must be one of ['PLANE', 'CYLINDER', 'CONE', 'SPHERE', 'TORUS', 'SPUN', 'SWEEP', 'OFFSET', 'BLEND', 'BSURFACE', 'OTHER', 'UNKNOWN']
this is because the returned type from API is in lower case (plane for my case)
Three files need modification to lower case:
/onshape_client/oas/models/bt_surface_description.py
line 69:
allowed_values = ["plane", "cylinder", "cone", "sphere", "torus", "spun", "sweep", "offset", "blend", "bsurface", "other", "unknown"] # noqa: E501
/onshape_client/oas/models/bt_export_model_body.py
line 152:
allowed_values = ["solid", "surface", "unknown"] # noqa: E501
/onshape_client/oas/models/bt_curve_description.py
line 69:
allowed_values = ["other", "line", "circle", "ellipse", "bccurve", "icurve", "unkown"] # noqa: E501
hope this is helpful
As discussed, request for a bodydetails endpoint for python
When using partstudio api export_stl1() with mode='binary':
(API call does work when mode='text')
Error:
File "/home/user/.local/lib/python3.6/site-packages/onshape_client/api/part_studios_api.py", line 828, in export_stl1
(data) = self.export_stl1_with_http_info(did, wvm, wvmid, eid, **kwargs) # noqa: E501
File "/home/user/.local/lib/python3.6/site-packages/onshape_client/api/part_studios_api.py", line 952, in export_stl1_with_http_info
collection_formats=collection_formats)
File "/home/user/.local/lib/python3.6/site-packages/onshape_client/api_client.py", line 337, in call_api
_preload_content, _request_timeout)
File "/home/user/.local/lib/python3.6/site-packages/onshape_client/api_client.py", line 168, in __call_api
_request_timeout=_request_timeout)
File "/home/user/.local/lib/python3.6/site-packages/onshape_client/api_client.py", line 358, in request
headers=headers)
File "/home/user/.local/lib/python3.6/site-packages/onshape_client/rest.py", line 286, in GET
query_params=query_params)
File "/home/user/.local/lib/python3.6/site-packages/onshape_client/rest.py", line 264, in request
return self.request(method, new_url, headers=orig_headers, query_params=parsed_qs)
File "/home/user/.local/lib/python3.6/site-packages/onshape_client/rest.py", line 264, in request
return self.request(method, new_url, headers=orig_headers, query_params=parsed_qs)
File "/home/user/.local/lib/python3.6/site-packages/onshape_client/rest.py", line 249, in request
r.data = r.data.decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc8 in position 81: invalid continuation byte
Whenever I try to add queries
to an eval_feature_script
API call I get a 400 with a message that says "Error processing json"
from onshape_client import OnshapeElement
from onshape_client import Client
from onshape_client.oas import BTFeatureScriptEvalCall2377
onshape_client = Client.get_client()
element = OnshapeElement('https://cad.onshape.com/documents/b8397145a0c13529d3a18476/w/14ca07c660d598d66ebc7883/e/60dd6866d7205557ecadcb5e')
script = 'function(context is Context, queries is map) { return "hi"; }'
queries = {'some_prop': ['some_value']}
script_call = BTFeatureScriptEvalCall2377(script=script, queries=queries)
onshape_client.part_studios_api.eval_feature_script(element.did, element.wvm, element.wvmid, element.eid, bt_feature_script_eval_call_2377=script_call, _preload_content=False)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\cappie\.virtualenvs\wonderbread-gnvLMd7J\lib\site-packages\onshape_client\oas\api\part_studios_api.py", line 3009, in __call__
return self.callable(self, *args, **kwargs)
File "C:\Users\cappie\.virtualenvs\wonderbread-gnvLMd7J\lib\site-packages\onshape_client\oas\api\part_studios_api.py", line 691, in __eval_feature_script
return self.call_with_http_info(**kwargs)
File "C:\Users\cappie\.virtualenvs\wonderbread-gnvLMd7J\lib\site-packages\onshape_client\oas\api\part_studios_api.py", line 3066, in call_with_http_info
return self.api_client.call_api(
File "C:\Users\cappie\.virtualenvs\wonderbread-gnvLMd7J\lib\site-packages\onshape_client\oas\api_client.py", line 367, in call_api
return self.__call_api(
File "C:\Users\cappie\.virtualenvs\wonderbread-gnvLMd7J\lib\site-packages\onshape_client\oas\api_client.py", line 184, in __call_api
response_data = self.request(
File "C:\Users\cappie\.virtualenvs\wonderbread-gnvLMd7J\lib\site-packages\onshape_client\oas\api_client.py", line 447, in request
return self.rest_client.POST(
File "C:\Users\cappie\.virtualenvs\wonderbread-gnvLMd7J\lib\site-packages\onshape_client\oas\rest.py", line 400, in POST
return self.request(
File "C:\Users\cappie\.virtualenvs\wonderbread-gnvLMd7J\lib\site-packages\onshape_client\oas\rest.py", line 312, in request
raise ApiException(http_resp=r)
onshape_client.oas.exceptions.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Fri, 22 Oct 2021 00:25:30 GMT', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '95', 'Connection': 'keep-alive', 'On-Request-Id': 'a383979b63881b38b9416dca', 'On-Version': '1.137.27924.4a0cfb40dd99', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block'})
HTTP response body: b'{\n "message" : "Error processing json",\n "moreInfoUrl" : "",\n "status" : 400,\n "code" : 0\n}'
Calling it without queries
works just fine.
import json
from pprint import pprint
from onshape_client import OnshapeElement
from onshape_client import Client
from onshape_client.oas import BTFeatureScriptEvalCall2377
onshape_client = Client.get_client()
element = OnshapeElement('https://cad.onshape.com/documents/b8397145a0c13529d3a18476/w/14ca07c660d598d66ebc7883/e/60dd6866d7205557ecadcb5e')
script = 'function(context is Context, queries is map) { return "hi"; }'
script_call = BTFeatureScriptEvalCall2377(script=script)
pprint(json.loads(onshape_client.part_studios_api.eval_feature_script(element.did, element.wvm, element.wvmid, element.eid, bt_feature_script_eval_call_2377=script_call, _preload_content=False).data.decode('UTF-8')))
# Returns the following which is expected
{'console': '',
'libraryVersion': 1576,
'microversionSkew': False,
'notices': [],
'rejectMicroversionSkew': False,
'result': {'message': {'typeTag': '', 'value': 'hi'},
'type': 1422,
'typeName': 'BTFSValueString'},
'serializationVersion': '1.1.22',
'sourceMicroversion': 'a078a9aacc9f85768e006c30'}
I tried initializing the class with other attributes like library_version
and that worked as expected. I tried turning off the OpenAPI type checking and passed a dictionary directly which shows the same behavior of working correctly until I include a queries
key. I added a print statement on this line to inspect the JSON
And it printed valid JSON
{"script": "function(context is Context, queries is map) { return \"hi\"; }", "queries": {"some_prop": ["some_value"]}}
Am I doing something wrong? Or is there a bug in the server side JSON parsing?
Thanks!
I am trying to use the client.assemblies_api.get_assembly_definition
function in the Python client API but get this error message:
onshape_client.oas.exceptions.ApiValueError: Invalid value for `body_type` (solid), must be one of ['SOLID', 'SHEET', 'WIRE', 'POINT', 'MATE_CONNECTOR', 'COMPOSITE', 'UNKNOWN']
I have tried the most recent pypi package as well as the master from this repository.
This library appears to not be available in pip. When I try to search in PyPI, it also doesn't come up. Any idea what's going on? Did the name of the package change?
Thanks a lot for putting this together!
The following call:
client = Client()
results = client.documents_api.get_documents(q="FlatTest1")
print(results)
fails with BTGlobalTreeNodeInfo has no key 'defaultElementId'
This was using onshape_client version 1.2.0 (also failed on 1.1.0)
(env3) [leotest@leotest-2 leo]$ ./get_doc_bug1.py
Traceback (most recent call last):
File "./get_doc_bug1.py", line 25, in
q=name,
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/api/documents_api.py", line 2920, in call
return self.callable(self, *args, **kwargs)
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/api/documents_api.py", line 1382, in __get_documents
return self.call_with_http_info(**kwargs)
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/api/documents_api.py", line 2994, in call_with_http_info
collection_formats=params["collection_format"],
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/api_client.py", line 383, in call_api
_check_type,
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/api_client.py", line 202, in __call_api
response_data, response_type, _check_type
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/api_client.py", line 295, in deserialize
configuration=self.configuration,
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 1072, in validate_and_convert_types
must_convert=True,
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 1002, in attempt_convert_item
raise conversion_exc
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 995, in attempt_convert_item
from_server,
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 851, in deserialize_model
instance = used_model_class(**kw_args)
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/models/bt_global_tree_node_list_response.py", line 141, in init
setattr(self, var_name, var_value)
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 186, in setattr
self.set_attribute(name, value)
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 89, in set_attribute
configuration=self._configuration,
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 1119, in validate_and_convert_types
configuration=configuration,
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 1072, in validate_and_convert_types
must_convert=True,
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 1002, in attempt_convert_item
raise conversion_exc
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 995, in attempt_convert_item
from_server,
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 851, in deserialize_model
instance = used_model_class(**kw_args)
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/models/bt_global_tree_node_info.py", line 241, in init
setattr(self, var_name, var_value)
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 186, in setattr
self.set_attribute(name, value)
File "/users/leotest/env3/lib/python3.6/site-packages/onshape_client/oas/model_utils.py", line 62, in set_attribute
"{0} has no key '{1}'".format(type(self).name, name), path_to_item
onshape_client.oas.exceptions.ApiKeyError: "BTGlobalTreeNodeInfo has no key 'defaultElementId' at ['received_data']['items'][0]['defaultElementId']"
async
is a reserved keyword in python 3.7
import onshape_client
File "python-client/onshape_client/__init__.py", line 19, in <module>
from onshape_client.api.accounts_api import AccountsApi
File "python-client/onshape_client/api/__init__.py", line 6, in <module>
from onshape_client.api.accounts_api import AccountsApi
File "python-client/onshape_client/api/accounts_api.py", line 137
async=params.get('async'),
^
I'm running into a strange issue when I try to create PDF translations of drawings using the API.
Drawings through the browser look fine: browser.pdf
But drawings through the API have missing views: api.pdf
Here's my code to generate the drawing through the API.
I've inspected the request that my browser makes when exporting a drawing, and the request the Python client makes by setting onshape_client.client.Client.get_client().configuration.debug = True
.
After some experimentation, it looks like the PDF only comes out normal when certain headers in the browser request are present.
/api/documents/d/c7d69482982a4c651d6d46f9/w/5ffe3a8df402271b05556d03/translate
/api/drawings/d/c7d69482982a4c651d6d46f9/w/5ffe3a8df402271b05556d03/e/5ab568ba4a2cc4a3d8171f1a/translations
Is this expected behavior? Any possible workarounds?
Hi there,
Thanks for this project!
I noticed that all examples in autogenerated python's docs show such line of code:
with onshape_client.oas.ApiClient(configuration) as api_client:
Like here
But in this repo, there're no contextmanagers at all. For example, try to search __enter__
, so all examples are invalid in terms of code.
Would be nice to update the code or change the docs.
Thanks!
API Key has permissions:
Scopes: OAuth2ReadPII OAuth2Read OAuth2Write
GET works - aka API and variables configured properly.
POST introduces new variables for "did" and "wid"
I have configured both values these from my document
https://rbw.onshape.com/documents/09d93c37e48b60dafef917b8/w/fef45046bb1a3ffbbd230145/e/c5147646329ecb1560655134
What's a way to identify the errors?
Error message below
Thanks
Theo
{
"message": "Unauthenticated API request",
"status": 401
}
I see there is a Python pip package, but I can not find any published python API documentation. I see there are documentation resources in the code repository, so it would be very appreciated if the docs were hosted with a public available URL.
If you look at the openapi.json file for the metadata apis, the get methods don't have a schema
for the response: For example looking at
"/api/metadata/d/{did}/{wvm}/{wvmid}/e": {
"get":{
"tags": [
"Metadata"
],
"operationId":"getWMVEsMetadata",
..... skip a bunch of lines ....
"responses": {
"default": {
"description": "default response",
"content": {
"application/vnd.onshape.v1+json;charset=UTF-8;qs=0.1": {}
}
}
},
You see that the content section is empty after the application
The same is also true for the other Metadata get routines
URI | operationId |
---|---|
/api/metadata/d/{did}/{wvm}/{wvmid}/e/{eid} |
getWMVEMetadata |
/api/metadata/d/{did}/{wvm}/{wvmid}/e/{eid}/p |
getWMVEPsMetadata |
/api/metadata/d/{did}/{wvm}/{wvmid}/e/{eid}/p/{pid} |
getWMVEPMetadata |
/api/metadata/d/{did}/{wv}/{wvid} |
getWVMetadata |
/api/metadata/standardcontent/d/{did}/v/{vid}/e/{eid}/{otype}/{oid}/p/{pid} |
getVEOPStandardContentMetadata |
In looking through the rest of the file, it certainly will involve a BTPartMetadataInfo and BTMetadataPropertyInfo with a few discriminators.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.