0

I have two processes running on different machines with different python versions (2.7 and 2.2 ). I need to know if its easy to pickle a python dictionary in python 2.7 and then unpickle in python 2.2 with same syntax or there is a difference.

msg = {'k1':'v1',...,'k100':'v100'}

pickling in python 2.7

msg = zlib.compress(cPickle.dumps(msg))
msg =  encrypt(msg)     # pls assume encrypt/decrypt methods md5 hashing
msg = cPickle.dumps(msg)

this is sent inside the url request sent via

urllib2.urlopen(urllib2.Request(destinationURL, msg))

Unpickling in python 2.2

msg = cPickle.loads(msg)
msg =  decrypt(msg) # decryption then md5 hashing (msg)
msg = cPickle.loads(zlib.decompress(msg))

this 'msg' is in unreadable format which the python 2.2 process is unable to use, so it is sending an error message which contains 'Message Format Invalid'

Actual issue is in Unpickling in python 2.2. Any help to properly format the string to get a response would be appreciated. I apologize for making some of you wait, I could not get access to remote machine yesterday, kindly reopen if you feel its not been answered elsewhere.

RAFIQ
  • 905
  • 3
  • 18
  • 32
  • 4
    Holy old version of Python, batman! With Pickle protocols 0 and 1 it should be possible, but Python 2.7 has object types Python 2.2 doesn't even have. Protocol version 0 is the default. What is the full traceback? – Martijn Pieters Aug 12 '14 at 09:35
  • What objects are you pickling and unpickling? How are you sending and receiving the data with urllib2? Can you show the full, exact error message? – user2357112 Aug 12 '14 at 09:36
  • 3
    Are you sure the problem is with the pickling and unpickling, and not the transfer? Have you looked at the `msg` on both sides? – jonrsharpe Aug 12 '14 at 09:37
  • If you just need it for string, why not just using the string? I mean, even if you save your pickled data to a file or you pipe it to the other, it's a string, do it directly ;) – enrico.bacis Aug 12 '14 at 09:58
  • please provide the code you're using to send and receive, I think it is the problem – mguijarr Aug 12 '14 at 12:00
  • For more complex things, use JSON, get a json library for 2.2. – Antti Haapala -- Слава Україні Aug 12 '14 at 12:25
  • Does the pickle->compress->encrypt process round trip on both systems? That is, if you serialize your data on Python 2.7, can you unserialize it successfully on the same system? Can you do the same thing (perhaps with dummy data) on the 2.2 system? Rather than it being some kind of version incompatibility, I'd guess there's a bug in the encryption somewhere. – Blckknght Aug 13 '14 at 05:16
  • yes it round trips on both systems, yes it works if both processes are in python 2.2, but now we have ported the program for python 2.7 but cant port other process (2.2) so this is issue has arised. – RAFIQ Aug 13 '14 at 05:20
  • you might get a more useful traceback if you used pickle instead of cPickle – Eevee Aug 13 '14 at 05:32
  • If you want to debug that, give an example with : initial mesg, result of pickle.dumps, result of compress, encrypt, and 2° pickle.dumps on both versions – Serge Ballesta Aug 13 '14 at 06:25
  • "md5 decryption" - what the crap? Are you aware that md5 is a hash algorithm, not a cipher? There's no such thing as md5 decryption. – user2357112 Aug 13 '14 at 08:10
  • @user2357112 sorry my mistake pls help now – RAFIQ Aug 13 '14 at 11:08
  • I think @user2357112's point is that you can't reverse an MD5 hash (not easily anyway). That's the whole point of a hash function! But I'd expect that to break your code when going between the programs running on the same version, so I'm not sure what the issue is. – Blckknght Aug 13 '14 at 11:10

0 Answers0