multi-model-server
multi-model-server copied to clipboard
Sys.stdout encoding should be utf-8
Problem use case: Given an MMS custom service prints some input for logging purposes, when the service receives json with unicode characters, the service errors out.
Steps to reproduce"
-
Create a dummy MMS service with a handler like:
def handle(data, context): if data is None: return print(data[0]["body"]) return ["Finished successfully."]
-
Send requests with ascii characters and it succeeds, but with unicode the service returns an error.
Test script
import requests
url="http://localhost:8080/predictions/classify"
headers={"Content-Type": "application/json"}
ascii_request={"test": "hi"}
unicode_request={"test": "你好"}
print(requests.post(url,json=ascii_request, headers=headers).content)
print(requests.post(url,json=unicode_request, headers=headers).content)
Results
python test.py
b'Finished successfully.'
b'{\n "code": 503,\n "type": "InternalServerException",\n "message": "Prediction failed"\n}\n'
- If you remove the print line from the service, both requests succeed.
Workaround To work around this behavior, services need to override the sys.stdout encoding.
import sys
sys.stdout.reconfigure(encoding='utf-8')
Reference to topic in different issue: https://github.com/awslabs/multi-model-server/issues/850#issuecomment-566678665
I am not clear on this. Is this an issue with the handler code or do you suspect it being a MMS issue? The error suggests that its a handler issue. Error seems to be coming as a part of exception thrown by the handler Code here
I went through the #850, I think. I understand the issue a bit better now. This looks like a good solution as well. This should probably be picked up as a part of #845