dimanche 8 mai 2016

Invalid syntax errror on SQLite execute command

I've got the following python 3 code:

import sqlite3
import json

conn = sqlite3.connect('data.db')
c = conn.cursor()

types = json.load(open('marketTypes.json'))

for data in types['items']:
    c.execute('INSERT INTO marketTypes (id, name, href) VALUES (?, ?, ?)', 
            (data['id_str'], data['type']['name'], data['type']['href'])


The database has already been created with a marketTypes table and 3 fields; id, name and href.

The json file looks like so, the first two fields that is, it is quite a long file.

{'items': [{'id': 18,
        'id_str': '18',
        'marketGroup': {'href': 'http://ift.tt/1Oa7htg',
                        'id': 516,
                        'id_str': '516'},
        'type': {'href': 'http://ift.tt/21MY1xB',
                 'icon': {'href': 'http://ift.tt/1Oa7eNW'},
                 'id': 18,
                 'id_str': '18',
                 'name': 'Plagioclase'}},
       {'id': 19,
        'id_str': '19',
        'marketGroup': {'href': 'http://ift.tt/21MXZpz',
                        'id': 517,
                        'id_str': '517'},
        'type': {'href': 'http://ift.tt/1Oa7eNY',
                 'icon': {'href': 'http://ift.tt/21MXZpB'},
                 'id': 19,
                 'id_str': '19',
                 'name': 'Spodumain'}},

When I run the python file I get:

File "sqlite.py", line 13
SyntaxError: invalid syntax

Any ideas on how to solve the issue? I apologize if the title is not as specific/helpful.


Aucun commentaire:

Enregistrer un commentaire