Need to send "dataset" as payload to mqtt broker

I am using tag change event to send the alarm data event from DB as dataset - query tag to send to the mqtt broker.
I am using the below code:

# Step 1: Read the dataset from the tag
tag_path = "[default]LMW/U12/Cylindrical/CMS:Spindle/Alarm"  # Replace with your actual tag path
tag_value = system.tag.read(tag_path).value  # Read the tag value
# Import the required module
 
import json
# Check if the tag value is a dataset
 
    # Step 2: Convert the dataset to a list of dictionaries
data_as_dicts = []
for i in range(tag_value.getRowCount()):
    row = tag_value.getRow(i)
    data_as_dicts.append(dict(zip(tag_value.getColumnNames(), row)))
    # Convert the list of dictionaries to a JSON string
payload = json.dumps(data_as_dicts)
    # Publish the payload
system.cirruslink.engine.publish("UNS_CMS", "LMW/U1/CYLINDRICAL/L1/CMS:Spindly_Temperature:M001:alarm", payload.encode(), 0, 0)

But it not working .
I query is , is it possible to send the send as dataset to mqtt BROKER?
If yes , Please help me with this
Error I was facing
com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File “”, line 14, in AttributeError: ‘com.inductiveautomation.ignition.common.BasicDatas’ object has no attribute ‘getRow’

at org.python.core.Py.AttributeError(Py.java:176)

at org.python.core.PyObject.noAttributeError(PyObject.java:965)

at org.python.core.PyObject.getattr(PyObject.java:959)

at org.python.pycode._pyx296.f$0(:21)

at org.python.pycode._pyx296.call_function()

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1703)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:804)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:859)

at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:752)

at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runCode(ProjectScriptLifecycle.java:840)

at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:251)

at com.inductiveautomation.ignition.common.script.TagChangeScriptExecutor$TagChangeExecutionCallback.execute(TagChangeScriptExecutor.java:198)

at com.inductiveautomation.ignition.common.util.SerialExecutionQueue$PollAndExecute.run(SerialExecutionQueue.java:102)

at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: org.python.core.PyException: AttributeError: ‘com.inductiveautomation.ignition.common.BasicDatas’ object has no attribute ‘getRow’

… 20 common frames omitted

The issue with your script is really more about how you are accessing the DataSet rather than sending it via MQTT. Via the MQTT publish API, you can publish anything that can be encoded as an array of bytes. So, you can publish a dataset. But, you must get it into an array of bytes first which is not happening in your script. See this doc from Inductive Automation on working with Datasets in Python: system.dataset | Ignition User Manual

Thank you for your reply. Will check on that.