Browser content display blocked by MIME type mismatch
See original GitHub issueIssue 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:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
Great, thanks.
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 frommimetypes.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 openregedit
and navigate toHKEY_CLASSES_ROOT\.js
and create a new string value (REG_SZ
) with nameContent Type
and valueapplication/x-test-123
, then I can reproduce the problem: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! 😃
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 seetext/plain
from a.js
file. I can’t reproduce this on my Linux machine; I seeapplication/javascript
as the responseContent-Type
, as expected.The
X-Content-Type-Options: nosniff
header is a security precaution, so we can’t remove that. Theif 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
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_detailsAlso, 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. 😃