Python Forum
Error binding parameter 0 - probably unsupported type.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error binding parameter 0 - probably unsupported type.
#1
Hoping I can get some help on this error:

c.execute("INSERT INTO USMoneySupply (MonetaryBase, M1, M2) VALUES (?, ?, ?)", sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

api_key = open('quandlapikey.txt', 'r').read()

def data_extract(code):
    data = quandl.get(code, authtoken=api_key, collapse='monthly')
    data['Y/Y, (%)'] = data['Value'].pct_change(12)*100
    return data

m2 = data_extract('FRED/M2')
m1 = data_extract('FRED/M1')
mb = data_extract('FRED/BOGMBASEW')

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

def create_table():
    c.execute("CREATE TABLE IF NOT EXISTS USMoneySupply(MonetaryBase REAL, MonetaryBasePer REAL, M1 REAL, M1Per REAL, M2 REAL, M2Per REAL)")

def data_entry():
    mb_data = mb['Value']
    mb_per = mb['Y/Y, (%)']
    m1_data = m1['Value']
    m1_per = m1['Y/Y, (%)']
    m2_data = m2['Value']
    m2_per = m2['Y/Y, (%)']
    c.execute("INSERT INTO USMoneySupply (MonetaryBase, MonetaryBasePER, M1, M1Per, M2, M2Per) VALUES (?, ?, ?, ?, ?, ?)",
              (mb_data, mb_per, m1_data, m1_per, m2_data, m2_per))
    conn.commit()

create_table()
data_entry()
c.close()
conn.close()
Thank you.
Reply
#2
please show the actual error traceback, complete and unaltered.
It contains valuable debugging information.
Reply
#3
Sorry about that. Is this better?

Error:
Traceback (most recent call last): File "C:/Users/duo1m/PycharmProjects/python_training/database/SQLite_training.py", line 35, in <module> data_entry() File "C:/Users/duo1m/PycharmProjects/python_training/database/SQLite_training.py", line 30, in data_entry c.execute("INSERT INTO USMoneySupply (MonetaryBase, MonetaryBasePER, M1, M1Per, M2, M2Per) VALUES (?, ?, ?, ?, ?, ?)", sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type. Process finished with exit code 1
Reply
#4
It's complaining about the type of MonetaryBase (I believe),
add just before insert statement:
print(f"Type MonetaryBase: {type(MonetaryBase)}")
What are the results?
Reply
#5
print(f"Type MonetaryBase: {type(MonetaryBase)}")
Error:
Traceback (most recent call last): File "C:/Users/duo1m/PycharmProjects/python_training/database/SQLite_training.py", line 38, in <module> print(f"Type MonetaryBase: {type(MonetaryBase)}") NameError: name 'MonetaryBase' is not defined
Reply
#6
It is the value of mb_data that you need to find out what it is
Reply
#7
(Jul-18-2020, 02:56 PM)Yoriz Wrote: It is the value of mb_data that you need to find out what it is

Like this:
def data_entry():
    mb_data = mb['Value']
    mb_per = mb['Y/Y, (%)']
    m1_data = m1['Value']
    m1_per = m1['Y/Y, (%)']
    m2_data = m2['Value']
    m2_per = m2['Y/Y, (%)']
    print(f"Type mb_data: {type(mb_data)}")
Output:
Type mb_data: <class 'pandas.core.series.Series'> Process finished with exit code 0
Reply
#8
I found a different way to achieve the desired result:

api_key = open('quandlapikey.txt', 'r').read()

def data_extract(code, column_name):
    data = quandl.get(code, authtoken=api_key, start_date='2000-01-01', collapse='monthly',)
    data['Y/Y, (%)'] = data['Value'].pct_change(12)*100
    data.rename(columns={'Value': column_name}, inplace=True)
    return data

m2 = data_extract('FRED/M2','M1')
m1 = data_extract('FRED/M1','M1')
mb = data_extract('FRED/BOGMBASEW', 'Monetary Base')

df_merged = [mb,m1,m2]
df = reduce(lambda  left,right: pd.merge(left,right,on='Date', how='outer'), df_merged).fillna('-')

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

def data_entry():
    df.to_sql('US Money Supply', conn, if_exists='replace')
    conn.commit()
    c.close()
    conn.close()

data_entry()
Here I get no errors and the output I wanted.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Type error in Cross_val_score Vicral 0 386 Jul-20-2021, 12:18 PM
Last Post: Vicral
  type error array BrianPA 2 838 Jan-17-2021, 01:48 PM
Last Post: BrianPA
  Error Message: TypeError: unhashable type: 'set' twinpiques 4 14,570 May-22-2019, 02:31 PM
Last Post: twinpiques
  Error:unsupported operand type(s) for ** or pow(): 'list' and 'int' mcgrim 3 7,201 Mar-22-2019, 01:29 PM
Last Post: buran
  Type Error Confusion Oliver 4 10,273 Dec-06-2017, 03:20 PM
Last Post: Oliver
  type error and access violation error pyopengl hsunteik 0 2,173 Nov-04-2017, 04:51 AM
Last Post: hsunteik
  AUCPR of individual features using Random Forest (Error: unhashable Type) melissa 1 1,980 Jul-10-2017, 12:48 PM
Last Post: sparkz_alot
  Why am I getting a type error? WagmoreBarkless 7 4,308 Jan-19-2017, 10:29 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020