简体   繁体   English

python 2 Web服务器本地主机错误。 服务器以非JavaScript MIME类型“ text / plain”进行响应

[英]python 2 web server local host error. The server responded with a non-JavaScript MIME type of “text/plain”

(First time) I used python -m SimpleHTTPServer 8000 using python 2.7.15 to generate a web server for my simple JavaScript game (still learning), but it seems that it has some error, which makes the canvas of my HTML file wont show. (第一次)我使用python -m SimpleHTTPServer 8000 python 2.7.15为我的简单JavaScript游戏生成了一个Web服务器(仍在学习中),但似乎有一些错误,这使得我的HTML文件的画布无法显示。

The JavaScript works totally fine in my GitHub page, but it won't show in local web server. JavaScript可以在我的GitHub页面上正常工作,但不会在本地Web服务器上显示。 https://jcloh98.github.io/jsgame/simplegame2.html https://jcloh98.github.io/jsgame/simplegame2.html

All the codes are exactly the same as the website. 所有代码均与网站完全相同。 That's all the code I used. 那就是我使用的所有代码。

This is the error showed in the console log. 这是控制台日志中显示的错误。

Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". 无法加载模块脚本:服务器以非JavaScript MIME类型“ text / plain”响应。 Strict MIME type checking is enforced for module scripts per HTML spec. 根据HTML规范对模块脚本强制执行严格的MIME类型检查。

https://jcloh98.github.io/jsgame/simplegame2.html https://jcloh98.github.io/jsgame/simplegame2.html

It is expected to show a black canvas with a aqua paddle at the bottom of the canvas, like https://jcloh98.github.io/jsgame/simplegame2.html 预计将在画布底部显示一个带有水色桨的黑色画布,例如https://jcloh98.github.io/jsgame/simplegame2.html

Instead of using python -m SimpleHTTPServer 8000 , create a .py file named "localhost.py" and run the .py file in the same directory of the webpage. 代替使用python -m SimpleHTTPServer 8000 ,创建一个名为“ localhost.py”的.py文件,然后在网页的同一目录中运行该.py文件。

localhost.py force the file with extension ".js" has "application/javascript" as the content type. localhost.py强制将扩展名为“ .js”的文件的内容类型设为“ application / javascript”。

localhost.py 本地主机

#Use to create local host
import SimpleHTTPServer
import SocketServer

PORT = 8000

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
Handler.extensions_map.update({
    ".js": "application/javascript",
});

httpd = SocketServer.TCPServer(("", PORT), Handler)

print "Serving at port", PORT
print(Handler.extensions_map[".js"])
httpd.serve_forever()

Thanks Bergi for helping me to solve this problem out. 感谢Bergi帮助我解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 加载模块脚本失败:服务器以“text/plain”的非 JavaScript MIME 类型响应。 严格的 MIME 类型检查 i - Failed to load module script: The server responded with a non-JavaScript MIME type of "text/plain". Strict MIME type checking i 返回Web服务器的html而不是python中的纯文本 - return html for a web server and not plain text in python Python Flask - 错误:“加载模块脚本失败。强制执行严格的 MIME 类型检查”。 适用于生产环境,而不是本地服务器 - Python Flask - Error: "Failed to load module script. Strict MIME type checking is enforced". Works on production, not on the local server Odoo模块在服务器上给出错误“文件类型纯文本文档(text / plain)” - Odoo module gives error “File type plain text document (text/plain) is not supported” on server Python SimpleHttpServer,如何以纯文本/ MIME类型返回不带扩展名的文件? - Python SimpleHttpServer, how to return files without extensions with plain/text mime type? 如何使用具有 MIME 类型“text/plain”的 Python 编写一个字符文件? - How to write a one character file using Python with mime type `text/plain`? Python Web服务器错误 - Python web server error 如何创建非本地服务器 Python? - How to create a non-local server Python? jinja2静态文件mime-type始终是text / plain - jinja2 static files mime-type always text/plain 内部服务器错误。 烧瓶 - Internal Server error. Flask
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM