inserting data into mysql

Hi, I’m having an issue trying to do an insert into mysql from Digi HP900 RF modem. I can grad the data from the device but it won’t read the data correctly to do the insert. Does anyone see any issues with this syntax here :

import mysql.connector;
from digi.xbee.devices import XBeeDevice

TODO: Replace with the serial port where your local module is connected to.

PORT = “/dev/ttyUSB1”

TODO: Replace with the baud rate of your local module.

BAUD_RATE = 115200

def main():
print(" ±----------------------------------------+“)
print(” | XBee Python Library Receive Data Sample |“)
print(” ±----------------------------------------+
")

device = XBeeDevice(PORT, BAUD_RATE)

try:
    device.open()

    def data_receive_callback(xbee_message):
        print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(),
                                 xbee_message.data.decode()))

    device.add_data_received_callback(data_receive_callback)
    xbee_message = device.read_data()
    connection = mysql.connector.connect(host='localhost',database='dbcapture',user='root',password='XXXX')
    cur = connection.cursor()
    cur.execute("insert INTO dbtable (`post_id`, `tempdata`, `split0`, `status`, `lastupdate`, `text`, `content`, `likes`) VALUES ('1', %s, 'split0', '2', CURRENT_TIMESTAMP, 'mynkey', 'joe', 'hello'),(xbee_message);")
    connection.commit()
    connection.close()
    print("Success")
    input()
    print("Waiting for data...

")

finally:
    if device is not None and device.is_open():
        device.close()

if name == ‘main’:
main()

Well, there are some syntax or logical errors with your code, you can try below code to fix these errors.

import mysql.connector
from digi.xbee.devices import XBeeDevice

# Replace with the serial port where your local module is connected to.
PORT = "/dev/ttyUSB1"

# Replace with the baud rate of your local module.
BAUD_RATE = 115200

def main():
    print(" ±----------------------------------------+")
    print(" | XBee Python Library Receive Data Sample |")
    print(" ±----------------------------------------+\n")

    device = XBeeDevice(PORT, BAUD_RATE)

    try:
        device.open()

        def data_receive_callback(xbee_message):
            print("From %s >> %s" % (xbee_message.remote_device.get_64bit_addr(), xbee_message.data.decode()))

        device.add_data_received_callback(data_receive_callback)
        xbee_message = device.read_data()
        connection = mysql.connector.connect(host='localhost', database='dbcapture', user='root', password='XXXX')
        cur = connection.cursor()
        data = (xbee_message.data.decode(),)
        cur.execute("INSERT INTO dbtable (`post_id`, `tempdata`, `split0`, `status`, `lastupdate`, `text`, `content`, `likes`) VALUES ('1', %s, 'split0', '2', CURRENT_TIMESTAMP, 'mynkey', 'joe', 'hello')", data)
        connection.commit()
        connection.close()
        print("Success")
        input("Waiting for data...\n")

    finally:
        if device is not None and device.is_open():
            device.close()

if __name__ == '__main__':
    main()

Thanks