1

enter image description here

Note location of cursor. At first I thought it was the lack of a semi colon, but as you can see, putting one in does not solve the problem or change the error. I compared this code to samples I found on http://initd.org/psycopg/docs/usage.html :

enter image description here

Based on this, I don't see the problem. FWIW, Pylint in ST3 has no issues with this code. thanks.

from os import getcwd, listdir
import psycopg2
from io import open

conn = psycopg2.connect("dbname=ktab user=malikarumi")
cur = conn.cursor()
path = getcwd()
filenames = listdir(path)

for filename in filenames:
with open(filename, 'rb') as f:
    f1 = f.read()
    cur.execute("INSERT INTO testable (title, content, chron_date, clock)\
    VALUES (%s, %s, %s, %s);"),
    (filename, f1, '2017-12-30', '23:59:00'),

conn.commit()
cur.close()
conn.close()
5
  • How can we possibly assist you with out the code around? ktab_odt4.py line 21 Commented Jan 2, 2018 at 5:16
  • @EvanCarroll: I can't seem to find the sweet spot on this issue. I get criticized for not putting enough. I put more, I get criticized for putting too much, I cut back, and on and on it goes..... Commented Jan 2, 2018 at 21:01
  • Don't you have a parenthesis mismatch in your python code there?.. Commented Jan 2, 2018 at 21:39
  • Or .. more correctly... Not mismatched, but misplaced parenthesis. Commented Jan 2, 2018 at 21:48
  • @JoishiBodio: Yes, it seems you are right. This is why I need another pair of eyes. The code ran, I was returned to the prompt with no further errors, but I got ZERO in the table! sigh..... I guess that should be a different issue and a different post with a different question. But thanks! Did you want to make it an answer? Commented Jan 3, 2018 at 2:11

1 Answer 1

1

You have misplaced parenthesis.

with open(filename, 'rb') as f:
    f1 = f.read()
    cur.execute(
        "INSERT INTO testable (title, content, chron_date, clock) VALUES (%s, %s, %s, %s);", # remove parenthesis here, which ends the execute call
        (filename, f1, '2017-12-30', '23:59:00')
    ) # move above parenthesis here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.