Python API: 401 Unauthorised when include_mate_connectors set to true in get_assembly_def arguments

anthony_cheung
anthony_cheung Member Posts: 6 ✭
edited May 2019 in General
https://github.com/onshape-public/python-client/blob/master/docs/AssembliesApi.md#get_assembly_definition

^ I've been using the above code to get the assembly definition but when I set include_mate_connectors in get_assembly_definition call I get a 401 error.
However it works fine if I remove them.

Wondering if anyone could help diagnose this issue. Thanks.

Comments

  • Ethan_K
    Ethan_K Member, Onshape Employees Posts: 57 image
    Thank you for trying out the experimental python client! I'm happy to help you here, but FYI, I posted an issue against the repo itself to track this issue here: https://github.com/onshape-public/python-client/issues/4
  • Ethan_K
    Ethan_K Member, Onshape Employees Posts: 57 image
    edited May 2019
    Just fixed this -- see here: https://github.com/onshape-public/onshape-clients/blob/master/python/test/test_assemblies_api.py One thing to note is that the inlcude_mate_connectors only actually does everything if you also set the include_features flag.
  • anthony_cheung
    anthony_cheung Member Posts: 6 ✭
    Apologies I was inaccurate. It was actually if you put in any kwargs. Thanks for the quick fix!
  • anthony_cheung
    anthony_cheung Member Posts: 6 ✭
    edited May 2019
    @ethan_keller769

    installed onshape-client with pip install (confirmed on 0.0.24)
    cloned the onshape-clients repo

    pipenv shell in onshape-clients/python then ran my get assembly definition code
    and now I'm getting Error 111 Connection Refused.

    tried without pipenv --> same error


    Let me know if I did something wrong, thanks.
  • Ethan_K
    Ethan_K Member, Onshape Employees Posts: 57 image
    edited May 2019
    Hmm... what did you plugin for your baseurl in your credentials file? It should be https://cad.onshape.com (without the /api). Specifically, your creds file should look like (of course with your own credentials plugged in): 
    prod:
    base_url: "https://cad.onshape.com"
    secret_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    access_key: XXXXXXXXXXXXXX default_stack: prod
  • anthony_cheung
    anthony_cheung Member Posts: 6 ✭
    edited May 2019
    In my code I added the second line:
    configuration = onshape_client.Configuration()
    configuration.host = "http://cad.onshape.com"<br>

    Fixes the issue 111 error because the URL is correct now. Default configuration.host is set to localhost in configuration.py.

    However, now I get a returned None from my API call. Any ideas?

    I copied the URL the program uses and it works in my browser.
  • Ethan_K
    Ethan_K Member, Onshape Employees Posts: 57 image
    That is because some of our APIs still don't have typing information migrated to openAPI. You'll need to add the keyword argument 
    _preload_content=false


  • anthony_cheung
    anthony_cheung Member Posts: 6 ✭
    @ethan_keller769 thanks for all the help