-1

I'm using python to access an sqlite db. I'm accessing a copy of the Firefox cookie db.

I'm trying to follow the advice giving here by jjm in: http://stackoverflow.com/questions/12325234/python-tuple-indices-must-be-integers-not-str-when-selecting-from-mysql-table

I would like to unpack the row variable into simple variable names. I do not understand what type of variable I am getting with row. Is it an array?

with con:
    cur = con.cursor()    
    # 
    cur.execute("SELECT \
        name, \
        value, \
        host, \
        datetime((expiry/1000000), 'unixepoch'), \
        expiry, \
        datetime((lastAccessed/1000000), 'unixepoch'), \
        datetime((creationTime/1000000), 'unixepoch') \
        FROM moz_cookies \
        WHERE baseDomain = 'apple.com' AND name = 's_ppv'")      

    rows = cur.fetchall()
    print ( len(rows) )


    for row in rows:
        if debug >= 1:
            # Indexes are 0 offset. 
            print ("row is = ")
            print (row)

            aName, aValue, aHost, aDisplayExpire, aExpire = row

failing on "aName, aValue, aHost, aDisplayExpire, aExpire = row" variable debug is set to 1. Here is the output.

1
row is = 
(u's_ppv', u'acs%253A%253Aadf%253A%253Aprofile%253Auser%2520profile%2520%2528en_US%2529%2C78%2C78%2C576%2C', u'.apple.com', u'2015-07-01 01:47:46', 1435715266000000L, u'2015-07-01 01:27:46', u'2015-06-15 16:12:15')
Traceback (most recent call last):
  File "./adjust-ASC-Time.bash", line 188, in <module>
    aName, aValue, aHost, aDisplayExpire, aExpire = row
ValueError: too many values to unpack
historystamp
  • 1,418
  • 4
  • 14
  • 24

1 Answers1

0

I chopped off the end of the vector.

aName, aValue, aHost, aDisplayExpire, aExpire = row[:5]

historystamp
  • 1,418
  • 4
  • 14
  • 24
  • Why are you specifying seven columns in the SELECT when you need only five? – CL. Jul 01 '15 at 17:54
  • That's how the code developed. I would have read less if I knew in advance that reading more would have caused problems. – historystamp Jul 08 '15 at 15:10