Высушил мозг. Не выполняется код
def saveSMS(self, body): """ Saving SMS to file """ global insert try: db = MySQLdb.connect(host="127.0.0.1", user="********", passwd="***********", db="sms", charset='utf8') sms = codecs.open('%s%s_%s_%s' % (dwgconfig.income_path, body['number'], body['port'], body['timestamp']), 'w', 'utf-8') sms.write('Number: %s\n' % body['number']) sms.write('Port: %s\n' % body['port']) sms.write('Time: %s\n' % body['timestamp']) if body['encoding'] == 0: insert = """INSERT INTO recievesms (phone_num, gw_port, time_in, content) VALUES (%s,%s,%s,%s);""" % ( (body['number']), (body['port']), (body['timestamp']), (body['content'])) sms.write('Content: %s\n' % body['content']) sms.write('SQL_Script encod_0: %s\n' % insert) elif body['encoding'] == 1: insert = """INSERT INTO recievesms (phone_num, gw_port, time_in, content) VALUES (%s,%s,%s,%s);""" % ( (body['number']), (body['port']), (body['timestamp']), (body['content'].decode('utf-16-be'))) sms.write('Content: %s\n' % body['content'].decode('utf-16-be')) sms.write('SQL_Script encod_1: %s\n' % insert) sms.close() cursor = db.cursor() cursor.execute(insert) db.commit() gc.collect() logger('[DATA] Received SMS from number %s' % body['number'], False) except: logger('[DATA] Received unknown SMS', False)
Вот, приходит смс, формируется файл с содержимым:
Number: +380*********
Port: 15
Time: 20150405235649
Content: Проверка с телефона 39
SQL_Script encod_1: INSERT INTO recievesms(phonenumsms, gwportsms, contentsms) values('+380*********', ‘15’, ‘20150405235649’, ‘Проверка с телефона 39’)