Hi Community,
I have created a custom Python operator which establishes an HTTP connection and reads the content using the Python package requests. The response is read using the response.content function and sent to the outport using api.outputs.OutputSoftgarden.publish(response.content,header=header). Outport type is of type scalar (com.sap.core.string). The response.content object is of type bytes.
Code:
from urllib.parse import urljoin
import requests
import pandas as pd
import io
def gen():
# Zusammensetzung der url für die Verbindung zum Softgarden
host = api.config.softgarden['connectionProperties']['host']
path = api.config.softgarden['connectionProperties']['path']
url = urljoin(host, path)
# Request senden und Response bekommen
response = requests.get(url)
# Zeichenkodierung auf UTF-8 setzen
response.encoding = 'utf-8'
# Response Inhalt speichern (hier handelt es sich um ein Objekt der <class 'bytes'>), welche in ein Dataframe umgewandelt werden soll
data_bytes = response.content
# Header erstellen
header = api.Record([host,path,url,0,0])
header = {"diadmin.softgarden.header":header}
api.logger.info(f"Header send:{header}")
api.outputs.OutputSoftgarden.publish(data_bytes,header=header)
api.set_prestart(gen)
I now want to create a new custom Python operator which will include the response.content object and transform it as Pandas Data Frame. What is the python code for this? I can't get anywhere using the body.get() function.
I could also read the response using the response.text function. Here the same question arises how I can read it in a new Python operator and transform it into a DataFrame.
Thanks for your effort in advance!
Many greetings
Geena
Request clarification before answering.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.