diff --git a/Wrapping/PythonCore/vtkPythonArgs.cxx b/Wrapping/PythonCore/vtkPythonArgs.cxx
index 1a82af0802..b733458975 100644
--- a/Wrapping/PythonCore/vtkPythonArgs.cxx
+++ b/Wrapping/PythonCore/vtkPythonArgs.cxx
@@ -95,13 +95,21 @@ bool vtkPythonGetStringValue(PyObject *o, T *&a, const char *exctext)
 {
   if (PyBytes_Check(o))
   {
+#if PY_VERSION_HEX >= 0x03070000
+    a = const_cast<char *>(PyBytes_AS_STRING(o));
+    return true;
+#else
     a = PyBytes_AS_STRING(o);
     return true;
+#endif
   }
 #ifdef Py_USING_UNICODE
   else if (PyUnicode_Check(o))
   {
-#if PY_VERSION_HEX >= 0x03030000
+#if PY_VERSION_HEX >= 0x03070000
+    a = const_cast<char *>(PyUnicode_AsUTF8(o));
+    return true;
+#elif PY_VERSION_HEX >= 0x03030000
     a = PyUnicode_AsUTF8(o);
     return true;
 #else
