cancel
Showing results for 
Search instead for 
Did you mean: 

Python3: How to add custom header?

SandeshK
Participant
0 Kudos
542

Hello All,

I am using a GEN2 graph to extract data from a CDS view on on-prem S/4HANA. I am using a Python3 operator to add a new custom header into the existing headers, which is basically the current year. However, it keeps erroring out with the following error:

"Record constructor does not supports <class 'str'>"

This error is raised when api.outputs.output.publish method is called in the script that I attached at the bottom of this post.

How can I add a custom header via Python?

Below is the script that I am using in the script:

import datetime

global now
now = datetime.datetime.now()
def on_input(msg_id, header, data):
    
    new_header = header.copy()
    new_header['myyear'] = str(now.year)
    data_val = data.get()
    api.outputs.output.publish(data_val, new_header)

api.set_port_callback("input1", on_input)

Accepted Solutions (0)

Answers (1)

Answers (1)

dsax
Explorer
0 Kudos

Please have a look at this example https://blogs.sap.com/2021/02/15/sap-data-intelligence-how-to-get-headers-of-cds-view/

Seems like it is supposed to be in JSON format