diff --git a/src/python_object.cpp b/src/python_object.cpp index ccb6ac8..91b7d77 100644 --- a/src/python_object.cpp +++ b/src/python_object.cpp @@ -147,11 +147,12 @@ std::optional PythonObject::asString() return result; } if (PyBytes_Check(object()) != 0) { - auto* result = PyBytes_AsString(object()); + const auto* result = PyBytes_AsString(object()); if (result == nullptr) { return std::nullopt; } - return std::string { result }; + auto length = PyBytes_Size(object()); + return std::string { result, 0, static_cast(length) }; } return std::nullopt; }