Trouble sending / receiving compressed data (using zlib) as HTTP POSTto server (in django)

Discussion in 'Python' started by subeen, Oct 3, 2009.

  1. subeen

    subeen Guest

    Hi,

    I am trying to send compressed data to a server written in django. But
    it shows error while decompressing the data in the server. After some
    experiment I found that the server is not receiving the exact data I
    am sending.

    data = 'hello, this is a test message this is another message'
    data = zlib.compress(data)
    # now it looks like: x��H����Q(��,V�D�����������T�p^~IFjL�e
    # length is 45

    in django (view) I receive it:
    data = request.POST['data']
    # now it looks like: x����Q(�,V�D�������^~IFjL�e
    # length is 34

    Can anybody help me understand the issue and how to get over?


    thanks,
    Subeen.
    http://love-python.blogspot.com
     
    subeen, Oct 3, 2009
    #1
    1. Advertising

  2. Re: Trouble sending / receiving compressed data (using zlib) as HTTP POST to server (in django)

    >>>>> subeen <> (s) wrote:

    >s> Hi,
    >s> I am trying to send compressed data to a server written in django. But
    >s> it shows error while decompressing the data in the server. After some
    >s> experiment I found that the server is not receiving the exact data I
    >s> am sending.


    >s> data = 'hello, this is a test message this is another message'
    >s> data = zlib.compress(data)
    >s> # now it looks like: x��H����Q(��,V�D����.�������T�p^~IFj.L.�.e
    >s> # length is 45


    Note: you can't just paste binary data in the message and expect
    something sensible. Better use the result of 'print data'.

    >s> in django (view) I receive it:
    >s> data = request.POST['data']
    >s> # now it looks like: x����Q(�,V�D���.����^~IFj.L.�.e
    >s> # length is 34


    >s> Can anybody help me understand the issue and how to get over?


    How did you post the data? If you post binary data you should indicate
    this with a proper mime type, like application/octet-stream. Otherwise
    it might be interpreted as text which it isn't.
    --
    Piet van Oostrum <>
    WWW: http://pietvanoostrum.com/
    PGP key: [8DAE142BE17999C4]
     
    Piet van Oostrum, Oct 3, 2009
    #2
    1. Advertising

  3. subeen

    subeen Guest

    Re: Trouble sending / receiving compressed data (using zlib) as HTTPPOST to server (in django)

    Thanks for your response.
    > How did you post the data? If you post binary data you should indicate
    > this with a proper mime type, like application/octet-stream. Otherwise
    > it might be interpreted as text which it isn't.
    > --

    I am trying to send the data using following code:
    ....
    opener = urllib2.build_opener()

    opener.addheaders = [

    ('User-Agent', 'python'),
    ('Content-Type', 'application/octet-stream'),
    ]
    data = zlib.compress(data)
    params = urllib.urlencode({'uid': uid, 'reqid': rid, 'data':
    data})
    usock = opener.open(url, params)
    resp = usock.read()

    usock.close()
    ....

    regards,
    Subeen.
     
    subeen, Oct 4, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TreatmentPlant
    Replies:
    4
    Views:
    417
    Default User
    Oct 17, 2007
  2. ojikay

    Sending Compressed Data To WebServer

    ojikay, Nov 8, 2004, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    299
    Dan Rogers
    Nov 19, 2004
  3. pintu
    Replies:
    0
    Views:
    212
    pintu
    Dec 14, 2006
  4. Jos Backus
    Replies:
    10
    Views:
    510
    Jeremy Bopp
    Feb 4, 2011
  5. stroumf

    receiving compressed data

    stroumf, Nov 21, 2006, in forum: Javascript
    Replies:
    1
    Views:
    107
    Jonas Raoni
    Nov 22, 2006
Loading...

Share This Page