写了一段非常简单的python httpserver,如下:
from BaseHTTPServer import BaseHTTPRequestHandler import urlparse class GetHandler(BaseHTTPRequestHandler): def do_GET(self): query = urlparse.urlparse(self.path).query params = dict([(k,v[0]) for k,v in urlparse.parse_qs(query).items()]) id = params['id'] self.send_response(200) self.end_headers() self.wfile.write('id='+id) return if __name__ == '__main__': from BaseHTTPServer import HTTPServer server = HTTPServer(('localhost', 8080), GetHandler) print 'Starting server, useto stop' server.serve_forever()
保存文件名为:wpt_proxy.py,目的取URL中GET参数值,执行时总是提示 IndentationError: unexpected indent。
如下图:
python版本2.7.6,编辑器Notepad++,解决方案: