5

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?

2
  • Have you tried repr() all the strings? Commented Mar 29, 2015 at 18:08
  • what is m, q or get_body? Commented Mar 29, 2015 at 18:10

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.