I’m getting an error when I use a tempfile.TemporaryFile and pass it to client.media.upload
If I use a vanilla filehandle with open() everything works.
example - this works:
tempfh = open('/tmp/tempfile', 'wb')
tempfh.write(field.data)
tempfh.close() #reopen?
tempfh = open('/tmp/tempfile', 'rb')
uploadTokenId = client.media.upload(tempfh)
tempfh is <_io.BufferedReader name='/tmp/tempfile'>
This does not work:
import tempfile
tempfh = tempfile.TemporaryFile(mode="w+b")
tempfh.write(field.data)
tempfh.seek(0)
uploadTokenId = client.media.upload(tempfh)
*** KalturaClient.exceptions.KalturaClientException: expected string or bytes-like object (-4)
tempfh is <_io.BufferedRandom name=14>
Both are file like objects and both have ‘read’ and ‘readlines’ methods and should be treated the same way.
Anyone also experience this? Anyway I can avoid the write to disk just to create a filehandle that the API seems to like?
Seems like a bug to me.
Full code can be seen here https://github.com/RadioFreeAsia/rfa.kaltura2/blob/7c9240063bf193af595840449748236f2c9bf460/src/rfa/kaltura2/kutils.py#L270