Help with sqlite3.OperationalError: unrecognized token

1,586 views
Skip to first unread message

Kit Macleod

unread,
Sep 11, 2013, 6:49:16 AM9/11/13
to scrap...@googlegroups.com
Hello,

I am struggling to solve what is probably a fairly simple error (creating a new table).  I am using your great service to schedule downloads of csv files using Python  (with permission) and would like to save each to a different table in the sqlite db you provide.  The code below works for your default table, but not when I change the table name.  I have looked at the help files for scraperwiki and dumptrack and tried to follow the traceback.  I am no SQL or python expert.  I have also looked around for solutions. I may need to use cursor.execute("""CREATE TABLE .  Any help you can provide would be great.  Code and error message below.  Thanks Kit

Code
#!/usr/bin/env python

import scraperwiki
import csv
from datetime import datetime

data = scraperwiki.scrape(
    "http://apps.sepa.org.uk/database/riverlevels/234291.csv")
reader = csv.reader(data.splitlines())
for row in reader:
    when = row[0]
    dt = datetime.strptime(when, "%d/%m/%Y %H:%M")
    level = float(row[1])
    print "%s river level was %f" % (when, level)
    data = {'datetime':dt, 'level':level}
    #scraperwiki.sql.save(unique_keys=['datetime'], data=data)
    scraperwiki.sql.save(unique_keys=['datetime'], data=data, table_name="234291")

Error

Traceback (most recent call last):

  File "./code/scraper", line 21, in <module>

    scraperwiki.sql.save(unique_keys=['datetime'], data=data, table_name="234291")

  File "/usr/local/lib/python2.7/dist-packages/scraperwiki/sqlite.py", line 33, in save

    dt.create_index(unique_keys, table_name, unique = True, if_not_exists = True)

  File "/usr/local/lib/python2.7/dist-packages/dumptruck/dumptruck.py", line 168, in create_index

    self.execute(sql % params, **kwargs)

  File "/usr/local/lib/python2.7/dist-packages/dumptruck/dumptruck.py", line 136, in execute

    self.cursor.execute(sql, *args)

sqlite3.OperationalError: unrecognized token: "234291_datetime"


Reply all
Reply to author
Forward
0 new messages