Handle the difference between PyNumber_ToBase(16) and PyString_Format("%x")
diff --git a/OpenSSL/util.c b/OpenSSL/util.c
index 76a4a25..661bb1d 100644
--- a/OpenSSL/util.c
+++ b/OpenSSL/util.c
@@ -77,6 +77,14 @@
         goto err;
     }
 
+#ifdef PY3
+    {
+        PyObject *hexbytes = PyUnicode_AsASCIIString(hex);
+        Py_DECREF(hex);
+        hex = hexbytes;
+    }
+#endif
+
     return hex;
 
   err: