Error creating query using python and pydomo

taylordomo ⚪️
edited March 2021 in APIs


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!


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!

  • taylordomo
    taylordomo ⚪️
    Answer ✓

    Hi, I wanted to follow up on this thread in case someone else has an issue running ds_query. For me, as of December 2022, if the query string has incorrect sql syntax, I receive this exception error:

    Exception: Error creating query: There was a problem executing the SQL query: Underlying service error: Internal Server Error

    I am not sure why it says it's an internal error because it's just a sql syntax error. Some tips for getting your syntax correct.

    • The simplest query you can run is to select all. If you have a dataset with less than 1 million rows, I would recommend this first to make sure your client id, secret id, and dataset id all check out.
    • that said, I'm betting the main use case for using ds_query is to actually select specific columns and filter using where. To select particular columns, if the column does not have any spaces in the name, you can type it how it's spelt.
    • if the column name has spaces, I've found that using back quotes works for me

    • then if you want to filter, obviously use the WHERE clause
    • one thing to be diligent on, is to make sure you have space between table and WHERE so I add a space or two after table (blue arrow)

    Hopefully this helps someone get started with this function!


  • 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"}