Table doesn't exist within schema

LabKey Support Forum
Table doesn't exist within schema bhaddock  2024-03-29 11:11
Status: Active
 

Hello,

I am trying to pull data from the table "HVTN SDMC Lab/Assay Data Status Tracker" using the labkey python API. The table is located at:
https://atlas.scharp.org/cpas/list/HVTN/Tools and Reports/SCHARP LDO/Assay Tracker/grid.view?listId=24

I have version 3.0.0 of the labkey package installed, and I have tried various combinations of variables which throw different errors. For example:

labkey_server = "atlas.scharp.org"
project_name = "HVTN"  # Project folder name
context_path = "cpas"
api = APIWrapper(labkey_server, project_name, context_path, use_ssl=True)

schema = "lists"
table =  "HVTN SDMC Lab/Assay Data Status Tracker"
result = api.query.select_rows(schema, table)

returns the error QueryNotFoundError: "404: The specified query 'HVTN SDMC Lab/Assay Data Status Tracker' does not exist in schema 'lists'" (full traceback attached).

When viewing the page on my browser (I'm using Chrome), the header says:
Lists / HVTN SDMC Lab/Assay Data Status Tracker
HVTN SDMC Lab/Assay Data Status Tracker [folder image] Assay Tracker
(see attached screenshot).

So I have also tried

labkey_server = "atlas.scharp.org"
project_name = "Assay Tracker"  # Project folder name
context_path = "cpas"
api = APIWrapper(labkey_server, project_name, context_path, use_ssl=True)

schema = "lists"
table =  "HVTN SDMC Lab/Assay Data Status Tracker"
result = api.query.select_rows(schema, table)

But then I get QueryNotFoundError: '404: No such project: /Assay Tracker'.

Going through https://github.com/LabKey/labkey-api-python I couldn't find any utilities that would list projects or tables within a schema -- is there such a method available? I'm sorry I know this is more of a question about the structure of the database I'm trying to access, but I can't figure out how to figure out that structure and thus the appropriate method arguments. Can you advise?

Thank you so much!
Beatrix

 
 
mohara responded:  2024-03-29 12:01

Hi Beatrix:

The parameter name in those examples in the python API docs is unfortunately misleading, and it's already on the list to get them updated. In fact there is new documentation for API wrapper itself available here:
https://github.com/LabKey/labkey-api-python/blob/develop/docs/api_wrapper.md

Instead of "project_name", the better way to name it is "container_path" because that's what needs to be provided. To access a list in:
https://atlas.scharp.org/cpas/list/HVTN/Tools and Reports/SCHARP LDO/Assay Tracker/grid.view?listId=24

You'd need to use something more like this (here I've renamed the parameter and fixed the comment):

labkey_server = "atlas.scharp.org"
container_path = "HVTN/Tools and Reports/SCHARP LDO/Assay Tracker"  # Full folder path
context_path = "cpas"
api = APIWrapper(labkey_server, container_path, context_path, use_ssl=True)

schema = "lists"
table =  "HVTN SDMC Lab/Assay Data Status Tracker"
result = api.query.select_rows(schema, table)

It's possible that the slash in the name of the list could also run into issues, so if that doesn't work, try accessing a list name without a slash in it.

A really good way to get a 'starter' snippet of python for any table is to use the Export button, choose Script, and select Python. Clicking 'create script' will then give you the APIWrapper you need to get to that data.
In a local example I just tried, it's also possible you'll need to escape the slashes in the path, if the snippet I provided above doesn't work: i.e.:

container_path = "HVTN\/Tools and Reports\/SCHARP LDO\/Assay Tracker"  # Full folder path

Hopefully that helps,

--Molly

 
bhaddock responded:  2024-03-29 12:50

Omg that export option is so helpful, thank you! The code snippet you provided worked perfectly, and the exported code snippets I tried worked when I removed the backslashes.

Thanks!