How to set MIMETYPES on server

Hi i have a problem similar to this one: I need to be able to set the mime-type of ogg files so that it plays without problems on the browser. How do i set these mimetypes on pythonanywhere ? Please help me resolve this issue.


Hi there -- a few questions:

  • How are you serving the files? That is, ss it from a static file, or a web application you've written?
  • If it's a static file, what's the file extension?

I'm serving out files with my django application. They are all static files and every other file works perfectly except for .ogg files. I know that the fix is to add the mimetype to the webserver. It currently serves it out as "application/octet-stream" where it should server it out as "application/ogg" Is there a way for me to add it here with pythonanywhere ?

references :

Please help me with this issue i am really thinking about buying premium for my website if all works well here.

Thanks for your reply.

That's strange. If you're using Django, it will ultimately use the Python mimetypes module to guess the type of the file. I've double-checked, and it looks like it should work for ogg files:

>>> import mimetypes
>>> mimetypes.guess_type("foo.ogg")
('audio/ogg', None)

Could you give me a URL on your site that shows the problem?

No i'm sure there is some kind of problem as i added the mimetype on my IIS server for .ogg as application/ogg and it worked perfect. This issue is only on Firefox so please visit and login with U:test/P:test and click on start survey. If your in firefox you will see the following error in firebug

"HTTP "Content-Type" of "application/octet-stream" is not supported. Load of media resource<filename>.ogg failed."

Also this is what i got in my bash:

import mimetypes
(None, None)

PS: I'm using django 1.4 by setting up a virtual env.

Thanks for the update! I'll investigate further, and report back as soon as I know more.

Sure, i really wish you can help me fix this issue. Thanks again.

Sorry for the slow reply. I think I've got it -- looks like a bug on our side, your sandbox was missing a file that tells the mimetypes module what the mapping from file extensions to mime types is. I've patched it for your account specifically, so if you try again now, it should work. If it does, could you let me know? Then we'll be able to make it a general fix for everyone.

Thanks for reporting this!

It still gives me the same error in firebug, i.e. OGG files are still coming down as "application/octet-stream".

That's strange. Have you restarted your web application? Also, could you try running mimetypes.guess_type("foo.ogg") in a console again?

I'm sorry.. yes restarted the server and it now works. Thanks a lot for the fix :) Although i still get "(None, None)" on trying to guess mimetype of a .OGG file.

No problem, I should have told you you'd need to restart the app!

It's actually rather odd that you're still seeing the problem when you use guess_type -- I'd expect both to work, or neither... Perhaps you're running the guess inside an old Python console? I think the mimetypes module tries to read the missing config file the first time you use it, and then caches the result until you exit the process.

Anyway, if the change I made solved the problem then we should get it done for everyone. It's pretty simple so I think I can promise it for the next release.

Sounds good :) Thanks for the quick fix.