Error creating query using python and pydomo

taylordomo
taylordomo ⚪️
edited March 2021 in Domo Developer

Hello,

When attempting to query a dataset with a simple query

query = {"sql": "SELECT * FROM table"}

I get this exception

Exception: Error creating query: {"status":400,"statusReason":"Bad Request","message":"Cannot deserialize instance of `java.lang.String` out of START_OBJECT token"


Using domo.ds_meta and domo.ds_get work fine, but I need to be able to query a larger dataset.


Thank for any help you can offer!

Tagged:

Best Answers

  • GrantSmith
    GrantSmith Indiana 🥷
    Answer ✓

    Hi @taylordomo

    Do you have any extra code / context for how you're calling ds_query?

    Are you passing your dictionary as the query or just the query string? Looking at the code for the query function it looks like it does the packaging automatically for you so you shouldn't need to pass in {"sql": "select * from table"} but rather just pass in your query itself "select * from table"

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • taylordomo
    taylordomo ⚪️
    Answer ✓

    Yes! Changing the query to a string worked. Now that I look around, I am not sure where I got the idea that I needed a dictionary. For others that have this same issue:

    query = "SELECT * FROM table"

    df = domo.ds_query(dataset_id=dataset_id,  query=query,  return_data=True)

    Is the correct code to get the querying to work. Query needs to be a string, not a dictionary.

    Appreciate the help!

Answers

  • jaeW_at_Onyx
    jaeW_at_Onyx Budapest / Portland, OR 🟤

    what happens when you don't use SELECT * and actually select column names?

    Jae Wilson
    Check out my 🎥 Domo Training YouTube Channel 👨‍💻

    **Say "Thanks" by clicking the ❤️ in the post that helped you.
    **Please mark the post that solves your problem by clicking on "Accept as Solution"
  • Hey, I appreciate the idea! I'm getting the same exception with any of these:

    {"sql": "SELECT name, id FROM table"}

    {"sql": "SELECT name, id FROM table Limit 3"}