Changed to allocate memory for buffer in Python