Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static content mime-type always text/plain #1045

Closed
praveenpuglia opened this issue May 4, 2014 · 17 comments
Closed

static content mime-type always text/plain #1045

praveenpuglia opened this issue May 4, 2014 · 17 comments

Comments

@praveenpuglia
Copy link

I have this weird problem. I am trying to include css files from the static directory, the browser downloads the content of the CSS file but it says the server is sending the css with mime-type:text/plain

It's best explained here - http://stackoverflow.com/questions/23452967/jinja2-static-files-mime-type-always-text-plain. I am unable to include any CSS file.

@danielchatfield
Copy link

Flask does not do this on a clean install with everything setup properly so without access to the code it will be very hard to actually work out what you are doing wrong.

@praveenpuglia
Copy link
Author

So here's the code

layout.html - http://pastebin.com/p0tERJtW
hello.py - http://pastebin.com/gQm3XXgz
index.html - http://pastebin.com/DFB7HRNU

This is bugging me like nothing has ever did.

@danielchatfield
Copy link

Can you run this and tell me what the output is:

import mimetypes

print(mimetypes.guess_type('style.css'))

@praveenpuglia
Copy link
Author

('text/plain', None)
This is what I get :(

@danielchatfield
Copy link

In chrome can you load http://localhost:5000/static/css/style.css?test (assuming that is the correct URL) and change the 'test' to a random string.

In the network tab of dev tools can you print screen the headers tab for the request.

@praveenpuglia
Copy link
Author

image

@danielchatfield
Copy link

in /flask/helpers.py you will find the following in send_file():

 if filename is not None:
        if not os.path.isabs(filename):
            filename = os.path.join(current_app.root_path, filename)
    if mimetype is None and (filename or attachment_filename):
        mimetype = mimetypes.guess_type(filename or attachment_filename)[0]
    if mimetype is None:
        mimetype = 'application/octet-stream'

can you add a print(mimetype) after it and then post what is printed to the terminal.

@praveenpuglia
Copy link
Author

I still get "text/plain"
127.0.0.1 - - [05/May/2014 20:52:05] "GET / HTTP/1.1" 200 -
This is the mime-type :: text/plain
127.0.0.1 - - [05/May/2014 20:52:05] "GET /static/css/style.css HTTP/1.1" 200 -
127.0.0.1 - - [05/May/2014 20:52:07] "GET /favicon.ico HTTP/1.1" 500 -

@danielchatfield
Copy link

I somehow misread this comment.

The python mimetypes module pulls the values from the registry on windows so somehow your registry has got a bit messed up.

If you open regedit and go to the HKEY_CLASSES_ROOT there should be a key .css/Content Type with value text/css. If there is then I have no idea what is happening, if there isn't then that is the confirmation that your registry is borked - I've got no real suggestions of what to do to fix it (save for manually adding each one you need again). If you have another windows machine then I guess you could export the HKEY_CLASSES_ROOT and then import it into the broken one although make sure you backup the registry first.

@praveenpuglia
Copy link
Author

My registry is indeed broken. Found text/plain. Changed it and it works fine.. Absolute thanks for that. But I suspect that NuSphere PhpED has done this. The default value for .css shows to be PhpED_css_file.

@ThiefMaster
Copy link
Member

Sounds like a good time to change editors ;)

@praveenpuglia
Copy link
Author

I work with ST3. That was a test to see whether NuSphere community went dead or not 'coz they just seem to be increasing the version number with hardly any new feature. That evaluation version screwed two days of my life.

@danielchatfield
Copy link

@praveenpuglia Can you close the issue :)

@dbstraight
Copy link

dbstraight commented Aug 31, 2018

You can also fix this with:

import mimetypes
mimetypes.add_type('text/css', '.css')

This may be preferable because it doesn't rely on system configuration.

@antnieszka
Copy link

I had the same issue with JS files 😂 Found out that windows registry had text/plain set. I wonder if it's a safe solution...

@rami-lab
Copy link

My registry is indeed broken. Found text/plain. Changed it and it works fine.. Absolute thanks for that. But I suspect that NuSphere PhpED has done this. The default value for .css shows to be PhpED_css_file.

And here , it was VisualStudio ;)

aaronsantiago added a commit to aaronsantiago/Eel that referenced this issue May 6, 2020
python-eel#49 python-eel#181 it seems like these issues weren't ever truly fixed.

It would be nice if Eel set the mimetypes on its own. According to pallets/flask#1045 this bug will happen for all Windows users.

The most common use for this would be to import JS modules. Chrome doesn't allow modules with incorrect mimetypes to be loaded without a registry edit.

mimetypes is a Python standard lib so there shouldn't be much impact.

Cheers!
samuelhwilliams pushed a commit to python-eel/Eel that referenced this issue May 24, 2020
#49 #181 it seems like these issues weren't ever truly fixed.

It would be nice if Eel set the mimetypes on its own. According to pallets/flask#1045 this bug will happen for all Windows users.

The most common use for this would be to import JS modules. Chrome doesn't allow modules with incorrect mimetypes to be loaded without a registry edit.

mimetypes is a Python standard lib so there shouldn't be much impact.

Cheers!
@arduinka55055
Copy link

i had the similar problem with .js files.
Thanks, you saved my time. What goes wrong with windows registry?
maybe, some installers do it?
anyway, Linux is less buggy :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants