TypeError:在字符串格式化期间,并非所有参数都已转换-OPC UA客户端到数据库连接

时间:2018-08-23 16:02:27

标签: multithreading mysql-python pymysql

问题描述

应该从opc ua客户端收集数据并将其传输到Maria DB数据库。排除了用于客户端数据收集的已定义功能。如果您需要它们,请问我。感谢您的帮助:)

# Connection MySQL database
[namenderSpalten_PW, Werte_PW] =  PW_main_a()
connection = pymysql.connect(host='127.0.0.1',
                             db='xxxx',
                             user='root',
                             password='')

#endless repetion of Pw and Pw functions + transfer of data to DB

while True:
        try:
            start_time = time.time()
            Pw= threading.Thread(target=PW_main_a,)
            Pt= threading.Thread(target=PT_main_a,)
            Pw.start()
            Pt.start()


            print("--- %s seconds ---" % (time.time() - start_time))
            # Connection MySQL database

            data_PW= ("INSERT INTO pull_winding "+
                "("+namenderSpalten_PW+")"+
                "\n VALUES ("+Werte_PW+")")

            data_PT= ("INSERT INTO pultrusion "+
                "("+namenderSpalten_PT+")"+
                "\n VALUES ("+Werte_PT+")")


            cursor = connection.cursor()    
            cursor.execute(data_PW,data_PT)
            connection.commit()

            print("over")
            print("--- %s seconds ---" % (time.time() - start_time))
            cursor.close()
            connection.close()
        except KeyboardInterrupt:
            print("bye")
            cursor.close()
            connection.close()    

输出

Traceback (most recent call last):
  File "xx\thread_main_PT_PW_test.py", line 302, in <module>
    cursor.execute(data_PW,data_PT)
  File "C:\Users\drj\Anaconda3\lib\site-packages\pymysql\cursors.py", line 168,
in execute
    query = self.mogrify(query, args)
  File "C:\Users\drj\Anaconda3\lib\site-packages\pymysql\cursors.py", line 147,
in mogrify
    query = query % self._escape_args(args, conn)
TypeError: not all arguments converted during string formatting

0 个答案:

没有答案