我有一个用于mp3流的python服务器。使用扭曲矩阵库
如果我尝试访问文件a.mp3
,它会正常工作
但是这个文件,例如衝.mp3
不起作用,它说“找不到文件”
此URL转义文件名为%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
。奇怪
目前没有回答
相关问题 更多 >
编程相关推荐