SQL fejl
Jeg får en fejl i SQL delen af dette stykke kode, resten virker. Hvad er der galt.def mainRate_v1(base_currency):
# Define the API endpoint and parameters
api_endpoint = "https://openexchangerates.org/api/latest.json"
params = {"app_id": '****', "base": base_currency}
# Send a GET request to the API endpoint and parse the JSON response
response = requests.get(api_endpoint, params=params)
exchange_rates = response.json()["rates"]
# Connect to the Access database
conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};'
r'DBQ=C:\Users\peter\OneDrive\Investering\Aktiver_Etoro.accdb;'
)
cnxn = pyodbc.connect(conn_str)
cursor = cnxn.cursor()
# Define the INSERT INTO statement
# Loop through the exchange rates and insert them into the database
for currency, rate in exchange_rates.items():
# Execute the SQL statement with the values
cursor.execute("INSERT INTO ExchangeRates (Currency, Rate, base_currency) VALUES (?, ?, ?)", (currency, rate, base_currency))
# currency, base_currency text field
# rate is double feild
# Commit the changes and close the database connection
cnxn.commit()
cursor.close()
cnxn.close()