最近使用python+apache搭建服务器,发现一个问题:对于POST请求+application/octet-stream的Content-Type,服务器总是返回501错误。
后来查看了mod_python/util.py脚本,发现设置的PythonHandler是mod_python.publisher,对于POST请求,其Content-Type有约束条件:
109 if req.method != "POST":
110 return
111
112 try:
113 clen = int(req.headers_in["content-length"])
114 except (KeyError, ValueError):
115 # absent content-length is not acceptable
116 raise apache.SERVER_RETURN, apache.HTTP_LENGTH_REQUIRED
117
118 if not req.headers_in.has_key("content-type"):
119 ctype = "application/x-www-form-urlencoded"
120 else:
121 ctype = req.headers_in["content-type"]
122
123 if ctype.startswith("application/x-www-form-urlencoded"):
124 pairs = parse_qsl(req.read(clen), keep_blank_values)
125 for pair in pairs:
126 # TODO : isn't this a bit heavyweight just for form field

在尝试用Python+Apache搭建服务器时,遇到POST请求Content-Type为'application/octet-stream'时返回501错误。分析mod_python.util.py脚本发现publisher不支持此类型。改用自定义handler后,所有请求被同一handler处理,为解决多脚本服务问题,采用handler总控动态设置PythonHandler。参考解决方案可在index.py中查看。
最低0.47元/天 解锁文章
1611

被折叠的 条评论
为什么被折叠?



