Op 05-11-13 10:56, Nick the Gr33k schreef: > Στις 5/11/2013 11:34 πμ, ο/η Nick the Gr33k έγραψε: >> Στις 5/11/2013 11:10 πμ, ο/η M.F. έγραψε: >>> On 11/05/2013 04:54 PM, Nick the Gr33k wrote: >>>> >>>> >>>> =============== >>>> data = cur.fetchall >>> data = cur.fetchall() >>> That is what the stack trace and Christ tried to inform you. >>>> for row in data: >>>> =============== >>>> >>>> The only thing i can understand by looking the above 2 lines is this: >>>> >>>> 'for' fails to iterate over 'data' because for some reason 'data' >>>> haven't resulted as a list of rows that can be iterated row by row. >>>> >>>> But that just doesn't help me much. >>> >> >> I see, but because of the traceback not being to express it more easily >> i was under the impression that data wasn't what i expected it to be. > > > Still similar error here: > > ================================= > # if first time for webpage; create new record( primary key is > automatic, hit is defaulted ), if page exists then update record > cur.execute('''INSERT INTO counters (url) VALUES (%s) ON > DUPLICATE KEY UPDATE hits = hits + 1''', page ) > cID = cur.lastrowid > > # fetch those columns that act as lists but are stored as strings > cur.execute('''SELECT refs, visits, downloads FROM visitors > WHERE counterID = %s and host = %s''', (cID, host) ) > data = cur.fetchone() > > # unpack data into variables > (ref, visit, download) = data > > # retrieve long strings and convert them into lists respectively > refs = ref.split() > visits = visit.split() > downloads = download.split() > > # add current strings to each list respectively > refs.append( ref ) > visits.append( visit ) > downloads.append( download ) > > # convert lists back to longstrings > refs = ', '.join( refs ) > visits = ', '.join( visits ) > downloads = ', '.join( downloads ) > > # save this visit as an entry into database > cur.execute('''INSERT INTO visitors (counterID, refs, host, > city, useros, browser, visits, hits = hits + 1, downloads) VALUES (%s, > %s, %s, %s, %s, %s, %s, %s, %s)''', > (cID, refs, host, city, useros, browser, visits, > hits, downloads) ) > ================================ > > > [Tue Nov 05 11:55:21 2013] [error] [client 176.92.96.218] File > "/home/nikos/public_html/cgi-bin/metrites.py", line 268, in <module> > [Tue Nov 05 11:55:21 2013] [error] [client 176.92.96.218] (ref, > visit, download) = data > [Tue Nov 05 11:55:21 2013] [error] [client 176.92.96.218] TypeError: > 'NoneType' object is not iterable > > > Now i have the parenthesis around fetchone(). > How the data cant be properly unpacked? > Did you read the documentation of fetchone?
-- Antoon Pardon -- https://mail.python.org/mailman/listinfo/python-list