question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Browser content display blocked by MIME type mismatch

See original GitHub issue

Issue description

For anyone who is interested, I had a problem running tensorboard in Windows preventing anything from displaying in every browser except for internet explorer. The error I received in Firefox Nightly is the following:

The resource from “http://localhost:6006/index.js” was blocked due to MIME type (“text/plain”) mismatch (X-Content-Type-Options: nosniff).

Tensorboard provides files from a prepared zip file (webfiles.zip), but these files were being provided with the ‘text/plain’ content-type header preventing browsers from using the javascript correctly. The ways to fix this is to go to the following file: tensoboard/backend/http_util.py and change to the following:

path_ext_split = request.path.split('.')
  if path_ext_split[-1] == 'js':
    content_type = 'application/javascript'
      
  if textual and not charset_match and mimetype not in _JSON_MIMETYPES:
    content_type += '; charset=' + charset

You could also disable nosniff by commenting out the following:

headers.append(('X-Content-Type-Options', 'nosniff'))

to

#headers.append(('X-Content-Type-Options', 'nosniff'))

I believe this might be similar to another issue referencing the projector.

The diagnose_tensorboard.py information is not useful. For this particular project, I’m attempting to use tensorboard for a pytorch project.

Environment information (required)

Diagnostics output
--- check: autoidentify
INFO: diagnose_tensorboard.py version d515ab103e2b1cfcea2b096187741a0eeb8822ef

--- check: general
INFO: sys.version_info: sys.version_info(major=3, minor=8, micro=0, releaselevel='final', serial=0)
INFO: os.name: nt
INFO: os.uname(): N/A
INFO: sys.getwindowsversion(): sys.getwindowsversion(major=10, minor=0, build=18362, platform=2, service_pack='')

--- check: package_management
INFO: has conda-meta: False
INFO: $VIRTUAL_ENV: None

--- check: installed_packages
WARNING: no installation among: ['tb-nightly', 'tensorboard', 'tensorflow-tensorboard']
WARNING: no installation among: ['tensorflow', 'tensorflow-gpu', 'tf-nightly', 'tf-nightly-2.0-preview', 'tf-nightly-gpu', 'tf-nightly-gpu-2.0-preview']
WARNING: no installation among: ['tensorflow-estimator', 'tensorflow-estimator-2.0-preview', 'tf-estimator-nightly']

--- check: tensorboard_python_version
Traceback (most recent call last):
  File "C:\Users\arosado\GitClone\tensorboard\tensorboard\tools\diagnose_tensorboard.py", line 470, in main
    suggestions.extend(check())
  File "C:\Users\arosado\GitClone\tensorboard\tensorboard\tools\diagnose_tensorboard.py", line 78, in wrapper
    result = fn()
  File "C:\Users\arosado\GitClone\tensorboard\tensorboard\tools\diagnose_tensorboard.py", line 246, in tensorboard_python_version
    from tensorboard import version
ModuleNotFoundError: No module named 'tensorboard'

--- check: tensorflow_python_version
Traceback (most recent call last):
  File "C:\Users\arosado\GitClone\tensorboard\tensorboard\tools\diagnose_tensorboard.py", line 470, in main
    suggestions.extend(check())
  File "C:\Users\arosado\GitClone\tensorboard\tensorboard\tools\diagnose_tensorboard.py", line 78, in wrapper
    result = fn()
  File "C:\Users\arosado\GitClone\tensorboard\tensorboard\tools\diagnose_tensorboard.py", line 253, in tensorflow_python_version
    import tensorflow as tf
ModuleNotFoundError: No module named 'tensorflow'

--- check: tensorboard_binary_path
INFO: which tensorboard: b'C:\\ProgramData\\Anaconda3\\Scripts\\tensorboard.exe\r\n'

--- check: addrinfos
socket.has_ipv6 = True
socket.AF_UNSPEC = <AddressFamily.AF_UNSPEC: 0>
socket.SOCK_STREAM = <SocketKind.SOCK_STREAM: 1>
socket.AI_ADDRCONFIG = <AddressInfo.AI_ADDRCONFIG: 1024>
socket.AI_PASSIVE = <AddressInfo.AI_PASSIVE: 1>
Loopback flags: <AddressInfo.AI_ADDRCONFIG: 1024>
Loopback infos: [(<AddressFamily.AF_INET6: 23>, <SocketKind.SOCK_STREAM: 1>, 0, '', ('::1', 0, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0, '', ('127.0.0.1', 0))]
Wildcard flags: <AddressInfo.AI_PASSIVE: 1>
Wildcard infos: [(<AddressFamily.AF_INET6: 23>, <SocketKind.SOCK_STREAM: 1>, 0, '', ('::', 0, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0, '', ('0.0.0.0', 0))]

--- check: readable_fqdn
INFO: socket.getfqdn(): 'DESKTOP-CLRUTHR'

--- check: stat_tensorboardinfo
INFO: directory: C:\Users\arosado\AppData\Local\Temp\.tensorboard-info
INFO: os.stat(...): os.stat_result(st_mode=16895, st_ino=1970324838089767, st_dev=2625741768, st_nlink=1, st_uid=0, st_gid=0, st_size=4096, st_atime=1577322690, st_mtime=1577322690, st_ctime=1577222989)
INFO: mode: 0o40777

--- check: source_trees_without_genfiles
INFO: tensorboard_roots (0): []; bad_roots (0): []

--- check: full_pip_freeze
INFO: pip freeze --all:
pip==19.3.1
setuptools==41.6.0
virtualenv==16.7.7
virtualenvwrapper-win==1.2.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
wchargincommented, Dec 27, 2019

Great, thanks.

How does mimetypes determine the mimetype? It doesn’t throw an exception even with an invalid url.

It guesses based on the filename given a pre-defined list of MIME types and extensions, not the file contents (as a magic database would).

The ['text/plain', None] result from mimetypes.guess_type indicates that your setup of Python or Windows is broken. On Windows, mimetypes reads from the (globally writable) registry, so it’s seems likely that another program has written a bad entry to the registry. Indeed, while I can’t repro this on a normal Windows install, if I open regedit and navigate to HKEY_CLASSES_ROOT\.js and create a new string value (REG_SZ) with name Content Type and value application/x-test-123, then I can reproduce the problem:

Screenshot of regedit

The fact that the mimetypes module from the Python standard library gives the wrong result suggests that this isn’t really a problem with TensorBoard proper. You may be interested in bpo-10551, which complains about this behavior but was marked as wontfix. I’d suggest fixing your corrupted registry and trying again; if you can’t track down the root cause, perhaps try asking on a community of Windows users (we don’t have much expertise there).

Good luck! 😃

1reaction
wchargincommented, Dec 27, 2019

Hi @amrosado! Thanks for the report. The content type is inferred from the file name, defaulting to application/octet-stream, so it’s surprising that you’d see text/plain from a .js file. I can’t reproduce this on my Linux machine; I see application/javascript as the response Content-Type, as expected.

The X-Content-Type-Options: nosniff header is a security precaution, so we can’t remove that. The if path_ext_split[-1] == "js" check should be handled by the MIME type detection logic instead. If your system isn’t reporting MIME types accurately, then this would presumably break for other extensions, too. We don’t want to special-case all of them if we can avoid it, so let’s instead try to find the root cause of the problem.

Could you tell us the output of

python -c "import mimetypes; print(list(mimetypes.guess_type('index.js')))"

on your machine, and also please confirm what the Content-Type header is on a response from http://localhost:6006/index.js? You can find the response headers in the Firefox dev tools as described here: https://developer.mozilla.org/en-US/docs/Tools/Network_Monitor/request_details

Also, please do provide the diagnose_tensorboard.py output. It may not seem useful to you, but clearly this issue depends on your environment, so cross-referencing the distinguishing factors among you and other people experiencing this problem (if any) can in fact be critical to debugging the root cause of issues like this. That’s why we ask for it in the first place. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resource blocked due to MIME type mismatch (X-Content ...
Now, after setting X-Content-Type-Options: nosniff, browser was forced to not do the MIME-sniffing and take the content-type as mentioned in response headers.
Read more >
Resource blocked due to MIME type mismatch (X ... - YouTube
JavaScript : Resource blocked due to MIME type mismatch (X- Content -Type-Options: nosniff) [ Gift : Animated Search Engine ...
Read more >
Blocked due to MIME type mismatch [#3275328] | Drupal.org
Strangely it's working on the D7 version of the site that I'm currently migrating to D9. Browser error: "The resource from “https://xxxxxxx.com/ ...
Read more >
Script blocked due to mime type mismatch - Marketing Nation
The underlying problem is a bug in IE9 which initially detects the CSS as a script, then barfs when it has non-script MIME...
Read more >
MIME type (“text/plain”) mismatch (X-Content-Type-Options
This is some sort of a conflict with nosniff — when that header is enabled, JavaScript files need to have the MIME type...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found