In Google app engine dev server, simplejson.dumps is sending data that contains header info that reads True,0,1

跟風遠走 提交于 2019-12-12 03:22:51

问题


The problem was with print statements. In app engine avoid print, use logger.

I have a python dict containing unicode strings. I need to send the dict to the javascript code to do page refresh. I am doing something like this.

map=getMap()
return Response(simplejson.dumps(map))

In the javascript code how ever I get following response,

True,0,1,2........... {map data}.

I was expecting only {map data} not True,0,1,2... as prefix. Do you know why is this happening. It only happens when there is unicode data present. With normal ascii data, it does not happen.

This is my real code.

    if data.has_key(requestTypeKey):
        logging.error(data[requestTypeKey].strip()==birdListKey) 
        if data[requestTypeKey].strip()==birdListKey:
            logging.error(language+data['countryID'])
              getter=BirdDataGetter({languageKey:language,countrykey:data[countrykey].strip()})
            birdlist=getter.getBirdList()
            return Response(simplejson.dumps(birdlist))

the data is utf-8 file can contains the following.

{'b322': u"R\xfcppell's Warbler"} 

(copied from actual file, \xfc is utf-8 encoded character ü. On the top of my class file I have

-- coding: utf-8 --

header.

I get following result in my client side,

True 0 1 2 3 4 5 6 7 8 9 10 11  Status: 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 10663  {"b322": "R\u00fcppell's Warbler"}

(Result truncated)

My javascript code is,

 $.post(urla,senddata,function(receiveddata){
        document.write(receiveddata);

});

Thanks.

来源:https://stackoverflow.com/questions/9123481/in-google-app-engine-dev-server-simplejson-dumps-is-sending-data-that-contains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!