compute_url = "http://3.104.37.217:80/"
compute_rhino3d.Util.url = compute_url
compute_rhino3d.Util.apiKey = ''
headers = {
"RhinoComputeKey": ""
}
class __Rhino3dmEncoder(json.JSONEncoder):
def default(self, o):
if hasattr(o, "Encode"):
return o.Encode()
return json.JSONEncoder.default(self, o)
gh_admin = open(r"./gh_scripts/admin.ghx", mode="r",
encoding="utf-8-sig").read()
gh_admin_bytes = gh_admin.encode("utf-8")
gh_admin_encoded = base64.b64encode(gh_admin_bytes)
gh_admin_decoded = gh_admin_encoded.decode("utf-8")
all_points = []
admin_curves = []
suburb_names = []
while True:
admin_response = requests.get(adminboundaries_url, params=params)
if admin_response.status_code == 200 and admin_response.json():
admin_data = json.loads(admin_response.text)
if "features" in admin_data:
for feature in admin_data["features"]:
suburb_name = feature['attributes']['suburbname']
geometry = feature["geometry"]
for ring in geometry["rings"]:
points = []
for coord in ring:
point = rh.Point3d(coord[0], coord[1], 0)
points.append(point)
all_points.append(point)
polyline = rh.Polyline(points)
curve = polyline.ToNurbsCurve()
admin_curves.append(curve)
suburb_names.append(suburb_name)
break # exit the loop if data is found
else:
time.sleep(0)
else:
# wait for some time before retrying
time.sleep(0)
maximum_suburb_num = len(suburb_names) - 1
suburb_name_to_index = {name: i for i,
name in enumerate(set(suburb_names))}
suburb_indices = list(suburb_name_to_index.values())
curves_to_include = admin_curves
# serialize curves
serialized_curves = []
for curve in curves_to_include:
serialized_curve = json.dumps(curve, cls=__Rhino3dmEncoder)
serialized_curves.append(serialized_curve)
# create list of dictionaries for each curve
curves_list = []
for i, curve in enumerate(serialized_curves):
curves_list.append(
{
"ParamName": "Curves",
"InnerTree": {
f"{{ {i}; }}": [
{
"type": "Rhino.Geometry.Curve",
"data": curve
}
]
}
}
)
max_dict = {
"ParamName": "Max",
"InnerTree": {
"{ 0; }": [
{
"type": "System.Int32",
"data": maximum_suburb_num
}
]
}
}
suburb_dicts = []
for i, suburb_name in enumerate(suburb_names):
suburb_index = suburb_indices[i]
suburb_dict = {
"ParamName": "Numb",
"InnerTree": {
f"{{ {i};0 }}": [
{
"type": "System.Int32",
"data": suburb_index
}
]
}
}
suburb_dicts.append(suburb_dict)
# update geo_payload with list of curves, point, and string inputs
geo_payload = {
"algo": gh_admin_decoded,
"pointer": None,
"values": curves_list + [max_dict]
}
for i, curve in enumerate(curves_list):
payload = copy.deepcopy(geo_payload)
payload["values"].append(curve)
payload["values"].append(suburb_dicts[i])
payload["values"].append(max_dict)
res = requests.post(compute_url + "grasshopper", json=payload, headers=headers)
response_object = json.loads(res.content)['values']
for val in response_object:
paramName = val['ParamName']
innerTree = val['InnerTree']
for key, innerVals in innerTree.items():
for innerVal in innerVals:
if 'data' in innerVal:
data = json.loads(innerVal['data'])
geo = rh.CommonObject.Decode(data)
att = rh.ObjectAttributes()
att.SetUserString("Suburb Name", str(suburb_names[i]))
att.LayerIndex = admin_layerIndex
model.Objects.AddMesh(geo, att)
model.Write('C:/Users/RivinduB/Desktop/output.3dm')
Hi, I’ve posted about this a couple of times but I wanted some help if possible. I’ve set up an AWS server with Rhino compute and it seems to be running fine. Get requests seems to at 200 but post requests return 500. When I run the same script locally with local host, it works perfectly. I have set the apikey (not in code for security), included in the headers for the post request as well. Res.content gets me this:
The problem is so odd because it works perfectly with local host but not with the AWS server. Any help would be useful thanks!

