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.
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.
I found this: https://forum.onshape.com/discussion/12415/receiving-401-unauthorized-when-trying-to-export-an-stl-or-parasolid-from-onshape-api
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.
Also it does work when I try the call manually in my browser where I am logged in my account. I have also tried different ways of encoding the configuration but it all returns 401. So do I have to put it in the request body despite what the glassworks explorer says?