Problem with python script: unsupported

Hi,

I’m currently making my first steps with the python api. I have created a small script, that should query a table using base.query(). But unfortunately i’m getting an error, that i cannot explain:

Exception has occurred: TypeError
unsupported operand type(s) for +: 'NoneType' and 'str'
  File "/grocy2seatable/run-export.py", line 34, in <module>
    query_result = base.query(sql_query, convert=True)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Here is my small code snippet, that causes the error:

for item in stock_items:
    print(f"processing {item.name}")
    # create seatable row
    str_id = str(item.id)
    sql_query = f"select Id, Name from Produkte where id = {str_id}"
   # when executing this line i get the error above
    query_result = base.query(sql_query, convert=True)

anyone can give me a hint what could be wrong?

I’m running my script from my local machine against the official cloud instance of seatable.

Hi @mfreudenberg.

I think it’s because id represents a string in your table. Therefore you have to put the value itself in single quotes like: id = '{str_id}'.

Hi @AkDk7 ,

thanks for the hint, but that didn’t seem to be the problem.

Another thing that caught my eye is you are converting item.id to a str. You could try to put item.id directly into the curly brackets.

Tried that also. I also deleted some columns from my table as i thought, it would cause an issue like here.

Current snippet is:

for item in stock_items:
  print(f"processing {item.name}")
  # create seatable row
  sql_query = f"select Id, Name from Produkte where id = '{str(item.id)}'"
  query_result = base.query(sql_query)

Does it raise the error, when you don’t run the query / comment last line in snippet?

No.
The script raises the error, when i try to access the api.

I also tried to get all rows from the table using the following snippet:

products_table_name = "Produkte"
product_rows = base.list_rows(products_table_name, "Default View")

It too raises the same error as it seems:

Exception has occurred: TypeError
unsupported operand type(s) for +: 'NoneType' and 'str'
  File "run-export.py", line 29, in <module>
    product_rows = base.list_rows(products_table_name, "Default View")
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

Am i doing something basically wrong?

I also reinstalled the dependencies using

pip install -r requirements.txt

my requirements.txt is as follows

pygrocy
socketIO-client-nexus
requests

This is how i initialize my base object:

seatable_url = environ["SEATABLE_URL"]
seatable_api_key = environ["SEATABLE_TOKEN"]
base = Base(seatable_api_key, seatable_url)

The values are taken from my .env file.

i forgot to authenticate with base.auth()

As long as it works now :slight_smile:

Yepp it works, after issuing a base.auth()
now my query looks like this:

sql_query = f"select Id, Name from {products_table_name} where Id = '{str(item.id)}'"
query_result = base.query(sql_query)

Thanks a lot!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.