我在 GAE 上托管我的 Unity3d Web 应用程序时遇到问题。 当应用程序加载并且网络播放器开始请求 ".unity3d"文件时,我使用以下 python 脚本进行 HTTP 响应:
class UnityHandler(webapp.RequestHandler):
def get (self, q):
if q is None:
q = 'WebPlayer.unity3d'
path = os.path.join (os.path.dirname (__file__), q)
self.response.headers ['Content-Type'] = 'text/html'
self.response.out.write (template.render (path, {}))
def main ():
application = webapp.WSGIApplication (
[('/(.*html)?', MainHandler),
('/(.*unity3d)?', UnityHandler)
], debug=True)
util.run_wsgi_app (application)
它运行得不太好,它找到了文件,但 Unity 网络播放器给我一个“文件长度错误”的错误。
谁能告诉我问题出在哪里? 我认为这与设置“内容类型”有关,但我不知道如何解决?
谢谢,
萨默萨米
最佳答案
首先,我假设您打算缩进以 path =
开头的 3 行。
其次,我猜您的意图是将 url“/”路由到 WebPlayer.unity3d。但是,您的两个正则表达式都将与/匹配,因为斜线后的所有内容都是可选的; MainHandler 将收到请求,因为它是第一个。
第三,看起来您不仅要通过动态处理程序而且还要通过模板引擎来提供静态文件。为什么?如果您只是想逐字提供静态文件,请使用 static handlers .
假设您已将 .unity3d 文件放在名为 static 的目录中:
# render WebPlayer.unity3d on /
- url: /
static_files: static/WebPlayer.unity3d
upload: static/WebPlayer.unity3d
# match other .unity3d files
- url: /(.*\.unity3d)
static_files: static/\1
upload: static/(.*\.unity3d)
# match *.html and anything else
- url: .*
script: main.py
关于python - Unity3d - 在 Google App Engine 上托管,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7390954/