diff --git a/bindings/python/python_to_value.hpp b/bindings/python/python_to_value.hpp index da4830e8a..24c8e5556 100644 --- a/bindings/python/python_to_value.hpp +++ b/bindings/python/python_to_value.hpp @@ -35,7 +35,6 @@ #include #include - namespace mapnik { static mapnik::attributes dict2attr(boost::python::dict const& d) @@ -46,7 +45,26 @@ namespace mapnik { boost::python::list keys=d.keys(); for (int i=0; i < len(keys); ++i) { - std::string key = extract(keys[i]); + std::string key; + object obj_key = keys[i]; + if (PyUnicode_Check(obj_key.ptr())) + { + PyObject* temp = PyUnicode_AsUTF8String(obj_key.ptr()); + if (temp) + { + #if PY_VERSION_HEX >= 0x03000000 + char* c_str = PyBytes_AsString(temp); + #else + char* c_str = PyString_AsString(temp); + #endif + key = c_str; + Py_DecRef(temp); + } + } + else + { + key = extract(keys[i]); + } object obj = d[key]; if (PyUnicode_Check(obj.ptr())) {