2011-09-13 57 views
0

我在Django 1.3 +活塞API上有一個項目。 這是GET處理程序的代碼:Django活塞消息編碼問題

listen_resource = Resource(ListenHandler) 

urlpatterns = patterns('', 
    url(r'^listen/(?P<expression>.*)$', listen_resource), 
) 


class ListenHandler(BaseHandler): 
    def read(self, request, expression):    

     retval = {} 
     print expression 

     try: 
      j_data = simplejson.loads(expression) 

    ... 

GET請求通常是一個JSON格式的字符串是這樣的:

/api/listen/%7B%22act%22:%221%22,%22login%22:%22Terminal_001%22,%22passw%22:%2211223344%22,%22body%22:%22%7B%5C%22date%5C%22:%5C%222011-09-14%2016:34:26%5C%22,%5C%22link%5C%22:%5C%220%5C%22%7D%22%7D 

當我打印:

print expression 

在運行項目通過Eclipse IDE在開發服務器上,結果爲:

{"act":"1","login":"Terminal_001","passw":"11223344","body":"{\"date\":\"2011-09-13 16:59:31\",\"link\":\"0\"}"} 

,我可以從這個JSON格式的字符串創建對象:

j_data = simplejson.loads(expression) 

但是,儘管Apache服務器+ mod_wsgi的運行項目,其結果是:

{"act":"1","login":"Terminal_001","passw":"11223344","body":"{/"date/":/"2011-09-13 17:46:42/",/"link/":/"0/"}"} 

的反斜線被斜線和操作取代simplejson.loads(expression)正在引發異常:

<type 'exceptions.ValueError'> 
('Expecting , delimiter: line 1 column 64 (char 64)',) 

在Apache服務器conf文件中,我添加了這一行AllowEncodedSlashes On

請幫忙解決這個問題。

回答