diff -r 58086f0a953a Modules/socketmodule.c --- a/Modules/socketmodule.c Wed Jan 27 00:39:12 2016 +0100 +++ b/Modules/socketmodule.c Thu Jan 28 01:58:17 2016 +0100 @@ -4529,6 +4529,7 @@ gethost_common(struct hostent *h, struct PyObject *name_list = (PyObject *)NULL; PyObject *addr_list = (PyObject *)NULL; PyObject *tmp; + PyObject *name; if (h == NULL) { /* Let's get real error message to return */ @@ -4637,7 +4638,18 @@ gethost_common(struct hostent *h, struct goto err; } - rtn_tuple = Py_BuildValue("sOO", h->h_name, name_list, addr_list); +#ifdef MS_WINDOWS + /* Issue #26227: gethostbyaddr() returns a string encoded + * to the ANSI code page */ + name = PyUnicode_DecodeLocale(h->h_name); +#else + /* FIXME: is it correct to always decode from UTF-8? */ + name = PyUnicode_FromString(h->h_name); +#endif + if (name == NULL) + goto err; + rtn_tuple = Py_BuildValue("OOO", name, name_list, addr_list); + Py_DECREF(name); err: Py_XDECREF(name_list);