python-twitter
python-twitter copied to clipboard
Unable to specify media type with UploadMedia*()
trafficstars
parse_media_files uses mimetypes.guess_type so it can't work if your image does not ends up with a correct extension on the external server.
Maybe using the returned Content-Type would be useful too.
So like http://example.com/hello.jpe gets rejected or is this something else?
@jeremylow Yes.
Yes, mimetypes.guess_type relies on file extension. Why don't we use python-magic or filetype?
filetype is really simple to use, and it's totally compatible
import filetype
def main():
kind = filetype.guess('tests/fixtures/sample.jpg')
if kind is None:
print('Cannot guess file type!')
return
print('File extension: %s' % kind.extension)
print('File MIME type: %s' % kind.mime)
if __name__ == '__main__':
main()