Python服务器无法访问URL

时间:2018-05-22 22:57:19

标签: python

我有一个用于mp3流媒体的python服务器。使用Twisted Matrix库。

如果我尝试访问文件a.mp3,它可以正常工作。

但是这个文件,例如衝.mp3不起作用,它说“找不到文件”。

此转义网址的文件名为%E8%A1%9D.mp3,但无法访问。

如果我尝试使用unicode而不是符号来访问它,就像这个\u885d.mp3一样,它仍然会显示“找不到文件”。

这是代码,请注意我必须放request.path = request.path.replace('%20', ' '),因为这是它可以访问路径中有空格的文件的唯一方法。这不应该是我认为的正常行为。

class playMP3(Resource):
    isLeaf = True
    def render_GET(self, request):
        this=urlparse.urlparse(request.path)#scheme,netloc,path,query
        root,ext=os.path.splitext(this.path)
        filename=os.path.basename(request.path)
        fileFolder=request.path.replace(filename,"")
        self.serverRoot=os.getcwd()
        print (request.path)
        if ext==".mp3":
        request.path = request.path.replace('%20', ' ')
            thisFile=File(self.serverRoot+request.path)
            return File.render_GET(thisFile,request)

resource = playMP3()
factory = Site(resource)
reactor.listenTCP(8880, factory)
reactor.run()

我还试图放request.path = urllib.unquote(request.path),但不是将其解码为衝.mp3,而是ÞíØ.mp3。怪异。

0 个答案:

没有答案
相关问题