>>> from zope.mimetype.typegetter import smartMimeTypeGuesser
>>> smartMimeTypeGuesser(data=b'I am bytes', content_type='text/html')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/jmadden/Projects/VirtualEnvs/zope.file34/lib/python3.4/site-packages/zope/mimetype/typegetter.py", line 77, in smartMimeTypeGuesser
if data.startswith(prefix):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str
When the guessed mime type is 'text/html', then the smartMimeTypeGuesser wants to look through _xml_prefix_table
to see if this might actually be XHTML. But the (static) _xml_prefix_table
contains text strings on Python 3, so you get this TypeError. (There's another table that probably has the same issue for HTML).
File "//zope.file34/lib/python3.4/site-packages/zope/publisher/publish.py", line 115, in debug_call
return obj(*args)
File "//zope.file34/lib/python3.4/site-packages/zope/formlib/form.py", line 868, in __call__
self.update()
File "//zope.file34/lib/python3.4/site-packages/zope/formlib/form.py", line 849, in update
result = action.success(data)
File "//zope.file34/lib/python3.4/site-packages/zope/formlib/form.py", line 640, in success
return self.success_handler(self.form, self, data)
File "//zope.file34/lib/python3.4/site-packages/zope/formlib/form.py", line 970, in handle_add
self.createAndAdd(data)
File "//zope.file34/lib/python3.4/site-packages/zope/formlib/form.py", line 975, in createAndAdd
ob = self.create(data)
File "//zope.file/src/zope/file/upload.py", line 70, in create
updateBlob(ob, f)
File "//zope.file/src/zope/file/upload.py", line 151, in updateBlob
name=nameFinder(f))
File "/zope.file34/lib/python3.4/site-packages/zope/mimetype/typegetter.py", line 77, in smartMimeTypeGuesser
if data.startswith(prefix):
TypeError: startswith first arg must be bytes or a tuple of bytes, not str