Search code examples
pythonpostgresqlpsycopg2

TypeError: not all arguments converted during string formatting postgres


I tried to add data to the database (using psycopg2.connect):

cand = Candidate('test', datetime.now(), '[email protected]', '123123', "21", 'test', 'test', 'test', datetime.now(), "1", "1", 'test', 'M', "18", "2", "2")
db.addCandidate(cand)

my function adds:

def addCandidate(self, candidate):
    with self.connection.cursor() as cursor:
        cursor.execute("""INSERT INTO candidate ( name, pub_date, email, tel, age, proff, href, city, last_update, called_count, status, comment, sex, recrut_id, vacancy_id, level)
              VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""", (candidate.name, candidate.pub_date, candidate.email, candidate.tel,
                             candidate.age, candidate.proff, candidate.href, candidate.city, candidate.last_update, candidate.called_count, candidate.status, candidate.comment, candidate.sex, candidate.recrut_id,
                             candidate.vacancy_id, candidate.level))
        self.connection.commit()

I tried wrapping data in str, but nothing has changed. in pymysql.connect works fine


Solution

  • I solved my problem, I wrote 15 '%s', instead of 16