As an exercise, I'm pulling data from an API and inserting it into a psql database. I was initially following the default limit of 1000 entries per pull, but decided I wanted to try and get all of the data which is approximately 40K rows. After a bit of experimentation, I can pull 4800, but then I get the following:
Traceback (most recent call last):
File "data_pull.py", line 19, in <module>
postgres_db.Bike_Count.insert_many(data).execute()
File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3516, in execute
cursor = self._execute()
File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 2901, in _execute
sql, params = self.sql()
File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3484, in sql
return self.compiler().generate_insert(self)
File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 2084, in generate_insert
value = row_dict[field]
KeyError: <peewee.IntegerField object at 0x7f5b32c2c7f0>
data_pull.py
import json, requests, peewee
import postgres_db
endpoint = 'https://data.seattle.gov/resource/4xy5-26gy.json?$limit=4800'
response = requests.get(endpoint, headers={'X-App-Token': '(REMOVED)'})
if response.status_code == 200:
data = json.loads(response.text)
postgres_db.Bike_Count.create_table(True)
postgres_db.Bike_Count.insert_many(data).execute()
postgres_db.py
import peewee
psql_db = peewee.PostgresqlDatabase('database', user='my_username')
class Bike_Count(peewee.Model):
date = peewee.DateTimeField()
fremont_bridge_sb = peewee.IntegerField()
fremont_bridge_nb = peewee.IntegerField()
class Meta:
database = psql_db
I've looked at the tables online thinking there was an issue with an entry there but I can't find anything obvious. Thanks for the help.