- /*
- * PyString_AsString()'s returned string refers to an internal buffer
- * (not a copy), i.e. the data must not be modified, and the memory
- * must not be free()'d.
- */
- if (!(str = PyString_AsString(py_str))) {
- ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
- goto err_h_decref_str;
+ if (!(py_encstr = PyUnicode_AsEncodedString(py_str, "utf-8", NULL))) {
+ /* TODO: log level 4 debug message */
+ ret = SRD_ERR_PYTHON;
+ goto err_out;
+ }
+ if (!(str = PyBytes_AS_STRING(py_encstr))) {
+ /* TODO: log level 4 debug message */
+ ret = SRD_ERR_PYTHON;
+ goto err_out;