character encoding - How to encode a unicode string to utf-8 in python? -


i encountering error when getting response websocket connection:

    print type(json.dumps(data)) typeerror: 'unicode' object not callable 

also:

    print type(data) typeerror: 'unicode' object not callable 

and:

    print type(str(data)) typeerror: 'unicode' object not callable 

can teach me how encode data string utf-8?

you (or library use, more you) have overwritten variable type in global scope.

here i'm breaking stuff in same way:

>>> type(1) <type 'int'> >>> type(u'9') <type 'unicode'> >>> type('9') <type 'str'> >>> type = u'i' >>> type(1) traceback (most recent call last):   file "<stdin>", line 1, in <module> typeerror: 'unicode' object not callable 

to encode unicode string utf-8 bytestring, call .encode('utf-8'):

>>> u'€'.encode('utf-8') '\xe2\x82\xac' 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -