Search code examples
mysqlpython-2.7csvwampmysql-connector-python

DatabaseError: 1 (HY000): Can't create/write to file '2015-04-06 20:48:33.418000'.csv (Errcode: 13 - Permission denied)


I am designing an application in Python and trying to write to a CSV file, but I am getting this error:

DatabaseError: 1 (HY000): Can't create/write to file '2015-04-06 20:48:33.418000'.csv (Errcode: 13 - Permission denied)

The Code:

def generate_report(self):
        conn=mysql.connector.connect(user='root',password='',host='localhost',database='mydatabase')     
        exe2 = conn.cursor()
        exe2.execute("""SELECT tbl_site.Site_name, State_Code, Country_Code,Street_Address, instrum_start_date, instrum_end_date, Comment INTO OUTFILE  %s FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\\\' LINES TERMINATED BY '\\n'FROM tbl_site JOIN tbl_site_monit_invent ON site_id = tbl_Site_site_id """, (str(datetime.datetime.now()),))

I can run this code without any errors on a Mac, but I need it to work on Windows.

How can I resolve this error?


Solution

  • It was simply permission error.