Use Py_buffer API

Fixes: https://bugzilla.osafoundation.org/show_bug.cgi?id=13005