Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Trouble sending / receiving compressed data (using zlib) as HTTP POSTto server (in django)

Reply
Thread Tools

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

 
 
subeen
Guest
Posts: n/a
 
      10-03-2009
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�������^~IF jL�e
# length is 34

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


thanks,
Subeen.
http://love-python.blogspot.com
 
Reply With Quote
 
 
 
 
Piet van Oostrum
Guest
Posts: n/a
 
      10-03-2009
>>>>> subeen <(E-Mail Removed)> (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���.����^~IF j.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 <(E-Mail Removed)>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
 
Reply With Quote
 
 
 
 
subeen
Guest
Posts: n/a
 
      10-04-2009
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sending and Receiving HTTP data.... newbie TreatmentPlant C++ 4 10-17-2007 05:39 PM
sending data to another server and receiving data as response pintu ASP .Net Web Services 0 12-14-2006 09:36 AM
receiving compressed data stroumf Javascript 1 11-22-2006 03:04 AM
Having trouble sending/receiving Email Edw. Peach Computer Security 1 01-16-2006 12:46 PM
Sending Compressed Data To WebServer ojikay ASP .Net Web Services 1 11-19-2004 11:10 PM



Advertisments