when sending a grasshopper script saved as “.gh” to rhinocompute, it complains as follows:
Traceback (most recent call last):
File "c:\dev\_TDA\tda_rh_compute_tests_suite\gh_cloud_py\bridges_bim_model.py", line 47, in <module>
output = gh.EvaluateDefinition(gh_file, input_tree)
File "c:\dev\_TDA\tda_rh_compute_tests_suite\.venv\lib\site-packages\compute_rhino3d\Grasshopper.py", line 51, in EvaluateDefinition
definition = ghx.read()
File "C:\Python\Python38\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
File "C:\Python\Python38\lib\encodings\utf_8_sig.py", line 69, in _buffer_decode
return codecs.utf_8_decode(input, errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd4 in position 0: invalid continuation byte
Once saved as “.ghx” it works fine but the ghx file size is almost 30 times bigger. Any ideas as to why it doesn’t work as “.gh”?
stevebaer
(Steve Baer)
September 17, 2021, 12:35pm
3
I’m trying to figure out why you are hitting line 51 when using a file with a .gh extension. The code was written to do different things based on the file extension. What is the path that you are using for your definition?
args['pointer'] = definition
else:
encoded = None
if os.path.isfile(definition):
if(definition.endswith('gh')):
with open(definition, 'rb') as gh:
content_bytes = gh.read()
encoded = base64.b64encode(content_bytes)
else:
with io.open(definition, 'r', encoding='utf-8-sig') as ghx:
definition = ghx.read()
if not encoded:
encoded = base64.b64encode(definition.encode('utf-8'))
args['algo'] = str(encoded, 'utf-8')
args['values'] = [tree.data for tree in trees]
response = Util.ComputeFetch(url, args)
return response
@stevebaer - I figured it out.
The string comparison here needs to be case insensitive.
Our path to the gh file ended with GH (in uppercase).
Which also explains why it was kicking into evaluating the branch for .ghx files
stevebaer
(Steve Baer)
September 23, 2021, 5:42am
5
Thanks for letting me know. I added this to our bug tracker as something to fix at
opened 05:41AM - 23 Sep 21 UTC
checking for a .gh file is case sensitive. It shouldn’t be. See
https://discour… se.mcneel.com/t/rhinocompute-client-side-error-reading-gh-script/129885/2
1 Like