|
各位大神,小弟写了一个下载MYSQL LONG BLOB到文件的脚本,但是执行不通过,帮忙指点下啊:
import pymysql as lcdb
db = lcdb.connect(host="10.50.20.52",port=3306,user="root",password="mysql",database="mantis")
cur=db.cursor()
sql='select t.id,t.content from mantis_bug_file_table t where FROM_UNIXTIME(t.date_added,\'%Y-%m-%d\')>=\'2015-06-01\' limit 2'
#sql2='select t.bug_id,t.content from mantis_bug_file_table t where FROM_UNIXTIME(t.date_added,\'%Y-%m-%d\')>=\'2015-06-01\ and t.id='+xid+'limit 2'
try:
cur.execute(sql)
results=cur.fetchall()
#print('id')
for row in results:
xid=row[0]
print(xid)
cur.execute('select t.bug_id,t.content from mantis_bug_file_table t where FROM_UNIXTIME(t.date_added,\'%Y-%m-%d\')>=\'2015-06-01\' and t.id='+str(xid))
bugid,xcontent=cur.fetchone()
print(bugid)
#sys.stdin = open('E:\NEWHOPE\PHYTHON\test.doc','rb')
#xfile=open('E:\NEWHOPE\PHYTHON\test.doc','wb')
xfile=xcontent.read()
sys.stdout = file('E:\NEWHOPE\PHYTHON\test.doc','wb')
try:
sys.stdout.write(xcontent)
finally:
sys.stdout.close()
except Exception as ee:
raise ee
finally:
db.close()
报错如下:
File "<ipython-input-7-41e02a623faa>", line 21 sys.stdout = file('E:\NEWHOPE\PHYTHON\test.doc','wb') ^SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: malformed \N character escape
|
|