Hi guys,
We have tried to connect a hops component with the python script. There is this error Message: KeyError: ‘{0}’
[INFO] Solving using legacy API: <HopsComponent /berechnung [Integer → Berechnung → Integer] >
{‘InnerTree’: {‘{0}’: [{‘data’: ‘74801’, ‘type’: ‘System.Int32’}]},
‘ParamName’: ‘Integer’}
[INFO] 127.0.0.1 - - [20/May/2024 23:52:28] “POST /solve HTTP/1.1” 200 -
[INFO] 127.0.0.1 - - [20/May/2024 23:52:35] “GET /berechnung HTTP/1.1” 200 -
[INFO] 127.0.0.1 - - [20/May/2024 23:52:35] “GET /berechnung HTTP/1.1” 200 -
[INFO] 127.0.0.1 - - [20/May/2024 23:53:05] “GET /berechnung HTTP/1.1” 200 -
[INFO] 127.0.0.1 - - [20/May/2024 23:53:05] “GET /berechnung HTTP/1.1” 200 -
[INFO] 127.0.0.1 - - [20/May/2024 23:55:50] “GET /berechnung HTTP/1.1” 200 -
[INFO] 127.0.0.1 - - [20/May/2024 23:55:50] “GET /berechnung HTTP/1.1” 200 -
grasshopper:
Code:
from flask import Flask, request
import ghhops_server as hs
app = Flask(__name__)
hops = hs.Hops(app)
@hops.component(
"/berechnung",
name="Berechnung",
nickname="Berechnung",
description="Berechnung",
inputs=[
hs.HopsInteger("Integer", "Produktion", "Integer"),
],
outputs=[
hs.HopsString("String", "Eigenverbrauch", "String")
]
)
def berechnung(Produktion):
print(f"Received Produktion: {Produktion}")
if Produktion is None:
return "No data"
Eigenverbrauch = Produktion * 0.5
print(f"Calculated Eigenverbrauch: {Eigenverbrauch}")
return str(Eigenverbrauch)
if __name__ == "__main__":
app.run(debug=True)
cheers marco