Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:
  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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

lebenitolebenito Member Posts: 15
edited January 2023 in General
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.

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?

Answers

  • caden_armstrong2caden_armstrong2 Member, User Group Leader Posts: 127 ✭✭✭
    edited January 2023
    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.
  • lebenitolebenito Member Posts: 15
    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?

  • caden_armstrong2caden_armstrong2 Member, User Group Leader Posts: 127 ✭✭✭
    The API Call works in the browser?
    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.

  • lebenitolebenito Member Posts: 15
    @caden_armstrong I tried to get the web request with fiddler and firefox but the stl calls dont even show up no matter what I try. Some other calls

    My url encoding should be right as it works with other calls and when I manually put it in my browser where I am logged in so authorized.
  • william_marquis671william_marquis671 Member Posts: 1
    edited June 6
    Has anyone found a fix for this? I have the same issue where when I try and download a specific configuration from a Python app I get the {"Unauthenticated API request", "status":401} error. When I try downloading without any config with my python code it works just fine and when I paste the request download url with specific configuration in my browser .
  • martin_kopplowmartin_kopplow Member Posts: 502 PRO
    I also saw this one today. I was rendering at the time. It went away after a browser refresh.
Sign In or Register to comment.