Record writing errors
Clear headers on exception
Fix initing file.py multiple times
Only set mime if known