hI I am trying to upload a csv file to postgresql database using python
A table called "userspk" is already created in the database called "DVD"
below are the codes
import pandas as pd
import psycopg2 as pg2
conn = pg2.connect(database='DVD', user=xxx,password=xxx)
cur = conn.cursor()
def upload_data():
with open('/Users/Downloads/DVDlist.csv', 'r') as f:
next(f) #skips the header row
cur.copy_from(f, 'userspk', sep=',')
conn.commit()
upload_data()
keep getting this error. I would have thought it should be fairly straightforward. Something wrong with codes?
/Users/pk/.conda/envs/Pk/bin/python /Users/pk/PycharmProjects/Pk/SQL_upload_file.py
Traceback (most recent call last):
File "/Users/pk/PycharmProjects/Pk/SQL_upload_file.py", line 44, in <module>
upload_data()
File "/Users/pk/PycharmProjects/Pk/SQL_upload_file.py", line 37, in upload_data
next(f) # Skip the header row.
File "/Users/pk/.conda/envs/Pk/lib/python3.5/codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 5718: invalid start byte