---
title: "python IndentationError: unexpected indent 错误排查"
author: "willvvv"
date: "2015-08-13T22:17:29Z"
tags: []
categories: ["编程语言"]
slug: "python-indentationerror-unexpected-indent"
draft: false
lastmod: "2015-08-13T22:17:29Z"
id: 2235333
url: "https://willvvv.iteye.com/blog/2235333"
---

写了一段非常简单的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, use <Ctrl-C> to stop'
	server.serve_forever()
```

 

保存文件名为：wpt\_proxy.py，目的取URL中GET参数值，执行时总是提示  IndentationError: unexpected indent。

如下图：

![](http://dl2.iteye.com/upload/attachment/0110/9515/94df60ca-bbdb-3c3b-b4f7-97c453905107.png)  
 

 

python版本2.7.6，编辑器Notepad++，解决方案：

在Notepad++中：编辑--&gt;空白操作--&gt;空格 转 TAB(全部)

保存一下重新运行就可以了。。。很囧啊。。