
Untitled
By: a guest on
Jan 20th, 2012 | syntax:
Python | size: 1.46 KB | hits: 17 | expires: Never
# File "import_ftp_users-v1.py", line 21, in <module>
# "VALUES (%s, %s, '(read)(write)(view)(delete)(resume)(share)(slideshow)(rename)(makedir)(deletedir)'", (row_number+offset, path))
# File "/usr/lib/pymodules/python2.7/MySQLdb/cursors.py", line 174, in execute
# self.errorhandler(self, exc, value)
# File "/usr/lib/pymodules/python2.7/MySQLdb/connections.py", line 36, in defaulterrorhandler
# raise errorclass, errorvalue
#_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL #server version for the right syntax to use near '' at line 1")
#!/usr/bin/env python
import csv
import sys
import MySQLdb
conn = MySQLdb.connect(host="localhost",
user="crushlb",
passwd="adminpw111",
db="crushlb")
x = conn.cursor()
f = open(sys.argv[1], 'rb')
try:
reader = csv.reader(f)
offset = 27
for row_number, row in enumerate(reader):
username, password, path = row
x.execute("INSERT INTO `USERS` (`userid`, `username`, `password`, `server_group`) "
"VALUES (%s, %s, %s, 'MainUsers')", (row_number+offset, username, password))
x.execute("INSERT INTO `VFS_PERMISSIONS` (`userid`, `path`, `privs`) "
"VALUES (%s, %s, '(read)(write)(view)(delete)(resume)(share)(slideshow)(rename)(makedir)(deletedir)'", (row_number+offset, path))
finally:
f.close()