[Python] Background on this error at: http://sqlalche.me/e/9h9h

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am currently new to programming ; So the problem is i am not able to import csv file to my PostgreSQL database and below is my code:


    import os
    import csv​

    from sqlalchemy import create_engine
    from sqlalchemy.orm import scoped_session, sessionmaker

    engine = create_engine(os.getenv("DATABASE_URL"))
    db = scoped_session(sessionmaker(bind=engine))

    def main():
    b = open("books.csv")
    reader = csv.reader(b)
    for isbn, title, author, year in reader:
    db.execute("INSERT INTO books1(isbn, title, author, year) VALUES:)isbn, :title, :author,
    :year)",
    {"isbn":isbn, "title":title, "author":author, "year":year})

    print(f"{isbn} Added to {title} ")
    db.commit()


    if __name__ == "__main__":
    main()


    And error is shown as

    [SQL: INSERT INTO books1(isbn, title, author, year) VALUES(%(isbn)s, %(title)s, %(author)s, %
    (year)s)]
    [parameters: {'isbn': 'isbn', 'title': 'title', 'author': 'author', 'year': 'year'}]
    (Background on this error at: http://sqlalche.me/e/9h9h)


    Can any one help me... please !!!

    Continue reading...

Compartilhe esta Página