TypeError: must be string, not unicode

UserX

I have this code:

...
msgdict = {'datafile': datafile, 'mapper': mapper, 'reducer':reducer}
msg = cPickle.dumps(msgdict)
print msg   

The print msg I get this:

(dp1
S'mapper'
p2
(S's3n://myFolder/mapper.py'
p3
tp4
sS'datafile'
p5
(S's3n://myFolder/test.txt'
p6
tp7
sS'reducer'
p8
(S's3n://myFolder/reducer.py'
p9
tp10
s.

Then Im trying to get my content:

for i in range(count):
    m = q[0].read()
    # this print returns a object Message
    print m 
    # m.get_body()) returns the same of print msg above
    msg = cPickle.loads(m.get_body()) 

But Im having this errror:

msg = cPickle.loads(m.get_body())       
TypeError: must be string, not unicode

Someone knows how to solve this error?

A.J. Uppal

Try to replace that line with the following:

msg = cPickle.loads(str(m.get_body()))

By casting str() to m.get_body(), it makes sure that if the string is unicode, it converts it to a string.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

TypeError: must be unicode, not str in NLTK

From Dev

TypeError: must be unicode, not str in NLTK

From Dev

TypeError: Must be String, not list

From Dev

Python: TypeError: text must be a unicode or bytes

From Dev

TypeError: hash must be unicode or bytes, not None

From Dev

TypeError: write() argument 1 must be unicode, not str

From Dev

Django error with TypeError: must be unicode not str

From Dev

TypeError: hash must be unicode or bytes, not None

From Dev

TypeError at / string indices must be integers

From Dev

unicode() argument 2 must be string not None

From Dev

Python HMAC: TypeError: character mapping must return integer, None or unicode

From Dev

TypeError: list indices must be integers, not unicode - django python

From Dev

Json.dump failing with 'must be unicode, not str' TypeError

From Dev

TypeError: list indices must be integers, not unicode (Telepot retrieve name)

From Dev

TypeError: execv() arg 2 must contain only strings (subprocess and unicode)

From Dev

Python ---- TypeError: string indices must be integers

From Dev

TypeError: string indices must be integers datetime

From Dev

TypeError: float() argument must be a string or a number, not 'Tensor'

From Dev

TypeError: Key id must be a string or a number

From Dev

zeromq: TypeError: string indices must be integers, not str

From Dev

Scrapy: TypeError: string indices must be integers, not str?

From Dev

Node JS TypeError: Secret must be a string or buffer

From Dev

TypeError: Parameter url must be string, not object

From Dev

TypeError: string indices must be integers (Python)

From Dev

TypeError: float() argument must be a string or a number, not 'IntVar'

From Dev

Must use *unicode* string as text to tag, while tagging with TreeTagger?

From Dev

DatabaseError: The first argument to execute must be a string or unicode query in python

From Dev

Reading a JSON string | TypeError: string indices must be integers

From Dev

TypeError: coercing to Unicode: need string or buffer, file found

Related Related

  1. 1

    TypeError: must be unicode, not str in NLTK

  2. 2

    TypeError: must be unicode, not str in NLTK

  3. 3

    TypeError: Must be String, not list

  4. 4

    Python: TypeError: text must be a unicode or bytes

  5. 5

    TypeError: hash must be unicode or bytes, not None

  6. 6

    TypeError: write() argument 1 must be unicode, not str

  7. 7

    Django error with TypeError: must be unicode not str

  8. 8

    TypeError: hash must be unicode or bytes, not None

  9. 9

    TypeError at / string indices must be integers

  10. 10

    unicode() argument 2 must be string not None

  11. 11

    Python HMAC: TypeError: character mapping must return integer, None or unicode

  12. 12

    TypeError: list indices must be integers, not unicode - django python

  13. 13

    Json.dump failing with 'must be unicode, not str' TypeError

  14. 14

    TypeError: list indices must be integers, not unicode (Telepot retrieve name)

  15. 15

    TypeError: execv() arg 2 must contain only strings (subprocess and unicode)

  16. 16

    Python ---- TypeError: string indices must be integers

  17. 17

    TypeError: string indices must be integers datetime

  18. 18

    TypeError: float() argument must be a string or a number, not 'Tensor'

  19. 19

    TypeError: Key id must be a string or a number

  20. 20

    zeromq: TypeError: string indices must be integers, not str

  21. 21

    Scrapy: TypeError: string indices must be integers, not str?

  22. 22

    Node JS TypeError: Secret must be a string or buffer

  23. 23

    TypeError: Parameter url must be string, not object

  24. 24

    TypeError: string indices must be integers (Python)

  25. 25

    TypeError: float() argument must be a string or a number, not 'IntVar'

  26. 26

    Must use *unicode* string as text to tag, while tagging with TreeTagger?

  27. 27

    DatabaseError: The first argument to execute must be a string or unicode query in python

  28. 28

    Reading a JSON string | TypeError: string indices must be integers

  29. 29

    TypeError: coercing to Unicode: need string or buffer, file found

HotTag

Archive