Hi, I’m trying to run a script in python using the hops component & flask server.
We changed our folder structure so I also opened a new project & venv in PyCharm, downloaded all the necessary modules and copied the code to a new app.py file.
Now that I’m trying to run the code it returns with multiple errors:
(venv) PS C:\Users\###\APP_PY> flask run
* Debug mode: off
[INFO] WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
[INFO] Press CTRL+C to quit
[INFO] Solving using legacy API: <HopsComponent /compare [b,a -> CompareCsv -> result_path] >
[INFO] 127.0.0.1 - - [22/Mar/2023 09:29:10] "POST /solve HTTP/1.1" 500 -
[ERROR] Error on request:
Traceback (most recent call last):
File "C:\Users\###\APP_PY\venv\lib\site-packages\werkzeug\serving.py", line 333, in run_wsgi
execute(self.server.app)
File "C:\Users\###\APP_PY\venv\lib\site-packages\werkzeug\serving.py", line 320, in execute
application_iter = app(environ, start_response)
File "C:\Users\###\APP_PY\venv\lib\site-packages\flask\app.py", line 2551, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Users\###\APP_PY\venv\lib\site-packages\ghhops_server\middlewares\hopsflask.py", line 42, in __call__
response = self.handle_POST(request)
File "C:\Users\###\APP_PY\venv\lib\site-packages\ghhops_server\base.py", line 75, in handle_POST
res, results = self.solve(uri=uri, payload=data)
File "C:\Users\###\APP_PY\venv\lib\site-packages\ghhops_server\base.py", line 126, in solve
return self._process_solve_request(comp, payload)
File "C:\Users\###\APP_PY\venv\lib\site-packages\ghhops_server\base.py", line 192, in _process_solve_request
res, inputs = self._prepare_inputs(comp, payload)
File "C:\Users\###\APP_PY\venv\lib\site-packages\ghhops_server\base.py", line 241, in _prepare_inputs
value = in_param.from_input(in_param_data)
File "C:\Users\###\APP_PY\venv\lib\site-packages\ghhops_server\params.py", line 209, in from_input
for param_value_item in input_data["InnerTree"]["0"]:
KeyError: '0'
It used to work before, and the code works perfectly when separated from Hops/Flask.
What am I not getting here?
Having the same problem, I followed all the steps described in the video and on github. I’m using vscodium with a python 3.9.13 virtual environment. Don’t know what I’m missing either.
(GHPyLearn) PS G:\Mon Drive\PERSO\Rhinoceros\GHPython\learn> python app.py
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
* Serving Flask app 'app'
* Debug mode: on
[INFO] WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:5000
[INFO] Press CTRL+C to quit
[INFO] * Restarting with stat
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
[WARNING] * Debugger is active!
[INFO] * Debugger PIN: 420-487-630
[INFO] * Detected change in 'G:\\Mon Drive\\PERSO\\Rhinoceros\\GHPython\\learn\\app.py', reloading
[INFO] * Restarting with stat
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
'FLASK_ENV' is deprecated and will not be used in Flask 2.3. Use 'FLASK_DEBUG' instead.
[WARNING] * Debugger is active!
[INFO] * Debugger PIN: 420-487-630
[INFO] 127.0.0.1 - - [17/Apr/2023 22:53:54] "GET /pointat HTTP/1.1" 200 -
[INFO] 127.0.0.1 - - [17/Apr/2023 22:53:54] "GET /pointat HTTP/1.1" 200 -
[INFO] Solving using legacy API: <HopsComponent /pointat [Curve,t -> PointAt -> P] >
[INFO] 127.0.0.1 - - [17/Apr/2023 22:54:17] "POST /solve HTTP/1.1" 500 -
Traceback (most recent call last):
File "G:\Mon Drive\PERSO\Rhinoceros\GHPython\learn\GHPyLearn\lib\site-packages\flask\app.py", line 2551, in __call__
return self.wsgi_app(environ, start_response)
File "G:\Mon Drive\PERSO\Rhinoceros\GHPython\learn\GHPyLearn\lib\site-packages\ghhops_server\middlewares\hopsflask.py", line 42, in __call__
response = self.handle_POST(request)
File "G:\Mon Drive\PERSO\Rhinoceros\GHPython\learn\GHPyLearn\lib\site-packages\ghhops_server\base.py", line 75, in handle_POST
res, results = self.solve(uri=uri, payload=data)
File "G:\Mon Drive\PERSO\Rhinoceros\GHPython\learn\GHPyLearn\lib\site-packages\ghhops_server\base.py", line 126, in solve
return self._process_solve_request(comp, payload)
File "G:\Mon Drive\PERSO\Rhinoceros\GHPython\learn\GHPyLearn\lib\site-packages\ghhops_server\base.py", line 192, in _process_solve_request
res, inputs = self._prepare_inputs(comp, payload)
File "G:\Mon Drive\PERSO\Rhinoceros\GHPython\learn\GHPyLearn\lib\site-packages\ghhops_server\base.py", line 241, in _prepare_inputs
value = in_param.from_input(in_param_data)
File "G:\Mon Drive\PERSO\Rhinoceros\GHPython\learn\GHPyLearn\lib\site-packages\ghhops_server\params.py", line 209, in from_input
for param_value_item in input_data["InnerTree"]["0"]:
KeyError: '0'
Hello, I have the same issue with fresh install for python 3.8, flask & ghhops-server. I have also updated to the latest Hops version (v16 as of writing) in grasshopper.
I have also:
Attempted a python 3.11 install (ghhops-server incompatible)
Attempted initial pip 23.1 install (issue with setup.py install)
Found the same issue for a fresh python 3.10 install
I also changed the default tutorial route from pointat to times_pi, but to no avail; the error is identical.
@hops.component(
"/times_pi",
name="TimesPi",
description="Multiplies a number by pi",
inputs=[
hs.HopsNumber("t", "t", "The number to scale")
],
outputs=[hs.HopsNumber("n", "N", "number scaled by pi")],
)
def times_pi(t):
return 3.14159265 * t
Update:
I added some lines to log the data in the associated file in the ghhops-server install: ...\3.8_hops\\lib\\site-packages\\ghhops_server\\params.py.
Which shows the problem is that the non-tree access of the from_input method in _GHParam manually indexs input_data["InnerTree"] with the key "0", rather than "{0}".
(input_data["InnerTree"]["0"] rather than input_data["InnerTree"][r"{0}"] in params.py ~line 209)
After changing this out, the hops component works fine.
Assuming this is the extent of bug, it’d be great if this could be pushed to pypi
So now I am receiving a KeyError: ‘{0}’ - it would be better to implement a try method that will allow for different python versions. I’m on python 3.9, ghhops-sever 1.5.5, hops v0.15.5