Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Getting Unauthenticated API request 401 when exporting stl with different configuration
I am trying to export the stl file of a model with the python API. It works if I just import the normal stl file with out giving a query string for the configuration but doesn't when I want to export it with a different configuration, it gives me back the status 401 Unauthenticated API request.
Here is an example call I want to use:
The configuration query string works perfektly fine when I am creating a shaded view with this configuration.
It also works if I put this link manuelly in my browser where I am logged in my account but does not in my application.
Which seemingly has the same problem, but mine doesn't go to the status 307 but instead instantly gives back 401. After executing the code line for line it did not go to this if clause https://github.com/onshape-public/onshape-clients/blame/master/python/onshape_client/oas/rest.py#L271 (which seems like its there to solve the redirect problem) but skipped it and instantly had the 401 status.
I don't get why that happens .
I somehow can't post a comment, so I am writing it hier in the edit:
Hey @caden_armstrong thanks for your answer,You need to URL encode the configuration when using it in the URL.
You do not need to encode it when its in the body of the request.
But the export stl call is a GET request und does not have a request
body. It says in the documentation I have to put the configuration in
the url as a query string. I also looked at an example I found on this
forum where it is the same.
Tagged:
1
Answers
You do not need to encode it when its in the body of the request.
That would indicate that either the python call is not matching what is above, or your python app isn't authenticated properly with Onshape.
Try using tools like Fiddler (or chrome dev tools) to see what the exact web request your app is making, or using a tool like postman to debug the call.
My assumption that your configuration was incorrect was because the Onshape forums show your api call/link as unencoded, but clicking on it I can see that it is encoded properly.