marshal.loads ValueError

A

abcd

I have the following code which is sent over the wire as a string...

from time import time
class Foo:
def go(self):
print "Time:", time()


I get this code and store it as, "data"

data = receivePythonSource()

Then I try...

exec marshal.loads(data) in my_module.__dict__

However I get an error saying:
ValueError: invalid literal for __float__: om time import time
class Foo:
def go(self):

.....almost like when I try to marshal and exec it misses the first two
characters, "fr" ...any ideas?
 
B

Benjamin Niemann

Hello,
I have the following code which is sent over the wire as a string...

from time import time
class Foo:
def go(self):
print "Time:", time()


I get this code and store it as, "data"

data = receivePythonSource()

Then I try...

exec marshal.loads(data) in my_module.__dict__

However I get an error saying:
ValueError: invalid literal for __float__: om time import time
class Foo:
def go(self):

....almost like when I try to marshal and exec it misses the first two
characters, "fr" ...any ideas?

marshal is used to (de)serialize python objects from/to strings.
marshal.loads() tries to deserialize an encoded string back into a python
object - which does not make sense here.
What you probably want is:

exec data in my_module.__dict__


HTH
 
A

abcd

marshal is used to (de)serialize python objects from/to strings.
marshal.loads() tries to deserialize an encoded string back into a python
object - which does not make sense here.
What you probably want is:

exec data in my_module.__dict__

thanks that took care of it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,588
Members
45,100
Latest member
MelodeeFaj
Top