1

I am trying to make a connection to my (pysqlcipher) encrypted sqlite database but I am failing because PRAGMA key input is incorrect. I have my correct password 'test' in a separate .env file.

Even though everything should be correct I get the following ERROR message: Error while connecting to sqlite. Incorrect number of bindings supplied. The current statement uses 0, and there are 1 supplied.

How can I solve this? I think it is syntax error.

.env file

DATABASE_SECRET_KEY = test

PYTHON SCRIPT

import sqlite3
import os
from flask import Flask, render_template, jsonify, request, flash, redirect, url_for, session
from pysqlcipher3 import dbapi2 as sqlite3

sqliteConnection = sqlite3.connect('./database/test.db')
cursor = sqliteConnection.cursor()

PRAGMA_key = os.environ.get("DATABASE_SECRET_KEY")
cursor.execute("PRAGMA key = \'%s\';", [PRAGMA_key])

print("Successfully Connected to SQLite")

ERROR

Error while connecting to sqlite.

Incorrect number of bindings supplied. The current statement uses 0, and there are 1 supplied.
JeffA
  • 11
  • 1
  • always put full error message (starting at word "Traceback") in question (not comment) as text (not screenshot). There are other useful information. – furas Dec 17 '20 at 17:47
  • Maybe try string formatting `f"PRAGMA key = '{PRAGMA_key}';"`. As I know `execute` may not replace some values in query - for example it can't put table name to query `SELECT * FROM %s`. All for security reason. – furas Dec 17 '20 at 17:48
  • Furas, your solutions worked! Thank you! – JeffA Dec 19 '20 at 07:38

0 Answers0