I am trying to insert data retrieved from YahooFinance into a SQL Server database, using Python's pypyodbc.
I am using the code below:
import pypyodbc
import ystockquote
conn = pypyodbc.connect('DRIVER={SQL Server};SERVER=serv;DATABASE=TEST;UID=uid;PWD=pwd')
cur = conn.cursor()
var1 = ystockquote.get_historical_prices('GOOG','201403027','20140411')
data = var1[1:]
columnBased = [[data[i][j] for i in range(len(data))] for j in range(len(data[0]))]
cur.execute("INSERT INTO [TEST].[dbo].[StockData] (Date, OpenPrice, ClosePrice, High, Low, Volume, Adj_Close) VALUES (?,?,?,?,?,?,?,?,?,?,?,?", (data))
cur.commit()
cur.close()
This yields the error
Traceback (most recent call last):
File "file.py", line 32, in <module>
cur.execute("INSERT INTO [TEST].[dbo].[StockData] (Date, OpenPrice, ClosePrice, High, Low, Volume, Adj_Close) VALUES (?,?,?,?,?,?,?,?,?,?,?,?", (data))
File "file.py", line 1458, in execute
self._BindParams(param_types)
File "file.py", line 1263, in _BindParams
if param_types[col_num][0] == 'u':
TypeError: 'type' object has no attribute '__getitem__'
What might I be doing wrong? Note that I am a Python novice and have previously done such retrievals and database insertion using MATLAB.