The buffer format is:

byte 0: the selected qop.  1==auth, 2==auth-int, 4==auth-conf
byte 1-3: the max length for any buffer sent back and forth on this connection. (big endian)
the rest of the buffer: the authorization user name in UTF-8 - not null terminated.

So, In Python, I don't know how to do this other than what I did.  (I am not a python expert...)  What I did was first write the max length and authorization user name into the buffer, then I overwrote the first byte with the qop.  Since the max length is big endian, this is ok.  The first byte should be 0x00 anyway.  I could put in a check for that...