Forum Stats

  • 3,728,151 Users
  • 2,245,559 Discussions
  • 7,853,353 Comments

Discussions

TypeError: 'NoneType' object is not iterable (Python3 with Oracle 19c)

epipko
epipko Member Posts: 93 Blue Ribbon
edited August 2020 in Python

The following script runs fine till it hits upc_id, = cur.fetchone().

Could someone explain, please what may cause it? If I run the query in database, I get the result back (see below).

Is there a way to see exactly what Oracle runs, after variable substitution?

I suspect single quotes are not in place for bind variables, but how can I confirm?

import datetimeimport cx_Oracleimport dbline_item_sku = 'Y35FLPQ_034Y_M'x = line_item_sku.split("_")print (x)print ("Split-list len: "+ str(len(x)))if len(x) == 3:    sku_with_dimension = Falseelif len(x) == 4:    sku_with_dimension = Trueprint ("SKU with dimension: " + str(sku_with_dimension))style_id = x[0]color_id = x[1]size_id = x[2]if sku_with_dimension:    dimension_id = x[3]print ("Style: "+style_id) print ("Color: "+color_id) print ("Size: "+size_id)conn = db.connect('Galo')print ("Connected to: " + conn.version)cur = conn.cursor()upc_id = cur.var(str)print ("Assigned return var")if sku_with_dimension:    sql = ("""                  select upc_id                                                                                   from sku            where business_unit_id = '81'            and style_id = :1            and color_id = :2            and identifier_id = 'EA'            and size_id = :3            and dimension_id = :4        """)    cur.execute(sql,(style_id, color_id, size_id, dimension_id))else:    sql = ("""                  select upc_id                                                                                   from sku            where business_unit_id = '81'            and style_id = :1            and color_id = :2            and identifier_id = 'EA'            and size_id = :3                                """)    cur.execute(sql,(style_id, color_id, size_id))print ("Determined which query to run")upc_id, = cur.fetchone()print (upc_id)db.disconnect(conn, cur)

Here is the output

'Y35FLPQ', '034Y', 'M'] Split-list len: 3 SKU with dimension: False Style: Y35FLPQ Color: 034Y Size: M Connected to: 19.0.0.0.0 Assigned return value Determined which query to run Traceback (most recent call last):   File "c:/Python/code/test.py", line 66, in <module>    upc_id, = cur.fetchone() TypeError: 'NoneType' object is not iterable

If I run the query in database, I receive a result back:

enter image description here

Answers

Sign In or Register to comment.