1

I am encountering this error always when getting a response from a websocket connection:

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

also:

    print type(data)
TypeError: 'unicode' object is not callable

and:

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

Can anyone teach me how to encode the data string back to utf-8?

1 Answer 1

2

You (or a library you use, but more likely you) have overwritten the variable type in the global scope.

Here I'm breaking stuff in the 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 is not callable

To encode Unicode string into UTF-8 bytestring, call .encode('UTF-8'):

>>> u'€'.encode('utf-8')
'\xe2\x82\xac'
Sign up to request clarification or add additional context in comments.

1 Comment

Oh, thanks, i found it one of the functions I used. I'll be careful next time.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.