post_api.py 文件源码

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

项目:uicourses_v2 作者: sumerinlan 项目源码 文件源码
def do_POST(self):
        # http://stackoverflow.com/questions/4233218/python-basehttprequesthandler-post-variables
        ctype, pdict = cgi.parse_header(self.headers['content-type'])
        if ctype == 'multipart/form-data':
            postvars = cgi.parse_multipart(self.rfile, pdict)
        elif ctype == 'application/x-www-form-urlencoded':
            length = int(self.headers['content-length'])
            postvars = cgi.parse_qs(self.rfile.read(length), keep_blank_values=1)
        else:
            postvars = {}
        # print(postvars)
        if 'Username' not in list(postvars.keys()) \
                or 'Password' not in list(postvars.keys()):
            log('E', 'vali.', 'No credentials.')
            self.exit_on_error('No credentials.')
            return
        if not validate_id(postvars['Username'][0], postvars['Password'][0]):
            log('E', 'vali.', 'Wrong credentials.')
            self.exit_on_error('Wrong credentials.')
            return
        # print(postvars)
        try:
            dispatch(postvars)
            self.write_response({'Status': 'OK'})
        except:
            log('E', 'hand.', 'Handler throws an exception.')
            self.exit_on_error('Handler throws and exception.')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号