如何理解接口幂等性
413
2022-08-29
Python使用ThreadingTCPServer创建多线程代理
#coding=utf8from BaseHTTPServer import BaseHTTPRequestHandlerfrom SocketServer import ThreadingTCPServerimport gzipfrom StringIO import StringIOimport logginglogging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='proxy.log', filemode='w')class proxyHandler(BaseHTTPRequestHandler): def do_POST(self): while True: try: path = self.path if path.split("/")[-1] =="statistics": #获取post提交的数据 datas =gzip.GzipFile(fileobj=StringIO(self.rfile.read())).read() self.wfile.write(datas) logging.debug(datas) print datas except Exception,e: logging.error(e) finally: self.finish() def do_CONNECT(self): pass def do_GET(self): pass def test(): host='127.0.0.1' port=8888 try: server = ThreadingTCPServer((host, port), proxyHandler) print 'Welcome to the Server HTTP On %s Port %d...' %(host,port) server.serve_forever() except KeyboardInterrupt,e: logging.error(e) #print '^C received, shutting down server' server.socket.close()if __name__ == '__main__': test()
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~