Issue #16416: Fix compilation error
diff --git a/Python/fileutils.c b/Python/fileutils.c
index cba6696..94ab8e4 100644
--- a/Python/fileutils.c
+++ b/Python/fileutils.c
@@ -169,7 +169,9 @@
     if (unicode == NULL)
         return NULL;
 
-    bytes = _PyUnicode_AsUTF8String(unicode, "surrogateescape");
+    bytes = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
+                                 PyUnicode_GET_SIZE(unicode),
+                                 "surrogateescape");
     Py_DECREF(unicode);
     if (bytes == NULL) {
         PyErr_Clear();