api.py 文件源码

python
阅读 42 收藏 0 点赞 0 评论 0

项目:v2ex-tornado-2 作者: coderyy 项目源码 文件源码
def post(self):
        authenticated = False
        if 'Authorization' in self.request.headers:
            auth = self.request.headers['Authorization']
            decoded = base64.b64decode(auth[6:])
            authenticated = True
        if authenticated:
            self.response.out.write('OK')
        else:    
            site = GetSite()
            template_values = {}
            template_values['site'] = site
            template_values['message'] = "Authentication required"
            path = os.path.join(os.path.dirname(__file__), 'tpl', 'api')
            t = self.get_template(path,'error.json')
            output = t.render(template_values)
            self.set_status(401, 'Unauthorized')
            self.set_header('Content-type', 'application/json')
            self.set_header('WWW-Authenticate', 'Basic realm="' + site.domain + '"')
            self.write(output)

# Replies
# /api/replies/show.json
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号