Repository navigation
Description
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
Activity
wchargin commentedon 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’ssurprising that you’d see
text/plainfrom a.jsfile. I can’treproduce this on my Linux machine; I see
application/javascriptasthe response
Content-Type, as expected.The
X-Content-Type-Options: nosniffheader is a security precaution,so we can’t remove that. The
if path_ext_split[-1] == "js"checkshould 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-Typeheaderis 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.pyoutput. It may notseem 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. :-)
amrosado commentedon Dec 27, 2019
My diagnose_tensorboard.py output is included in the first post like asked for. I don't think I have it working correctly because it doesn't find my installed tensorboard module for the virtualenv I'm using.
My headers for index.js without changing the html_util.py:
Response:
Request:
The output of ``` python -c "import mimetypes; print(list(mimetypes.guess_type('index.js')))" ````:
How does mimetypes determine the mimetype? It doesn't throw an exception even with an invalid url.
wchargin commentedon Dec 27, 2019
Great, thanks.
It guesses based on the filename given a pre-defined list of MIME types
and extensions, not the file contents (as a
magicdatabase would).The
['text/plain', None]result frommimetypes.guess_typeindicatesthat your setup of Python or Windows is broken. On Windows,
mimetypesreads 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
regeditandnavigate to
HKEY_CLASSES_ROOT\.jsand create a new string value(
REG_SZ) with nameContent Typeand valueapplication/x-test-123,then I can reproduce the problem:
The fact that the
mimetypesmodule from the Python standard librarygives 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! :-)
amrosado commentedon Dec 27, 2019
Thanks for the explanation. I have this same problem on two different windows installations. After changing the value in my registry tensorboard works like expected.
wchargin commentedon Dec 27, 2019
Great; glad to hear it, and thanks for letting us know! Sounds like some
program installed on those machines is writing bad values to the
registry. Some related discussions:
At least one user is claiming that the errant application is Visual
Studio, which would be quite unfortunate.
turki123u commentedon Nov 28, 2025