473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Python compressed URL post

Hi,

I have spent most of the day on this so any help would be appreciated.

I have set up mod_deflate in Apache so that any input marked
content-type gzip from the client is automatically decompressed before
being forwarded on to the server-side java servlet.

The idea is that I compress a file on the client write it to the stream
and then it reaches the servlet decompressed through Apache. At the
moment when I try to open the URL it fails with an internal server
error, which I guess is because my code is wrong

import httplib, urllib2, StringIO, gzip

httplib.HTTPConnection.debuglevel = 1
filename = 'd:/myproject/schemas/samples/request.xml'
file = open(filename, 'r')

buf = file.read()

print 'decompressed request buffer size is ', len(buf)
zbuf = StringIO.StringIO()
zfile = gzip.GzipFile(mode = 'wb', fileobj = zbuf, compresslevel = 9)
zfile.write(buf);
zfile.close()
print 'compressed request file size is ', len(zbuf.getvalue())
request =
urllib2.Request('http://localhost/cocoon/compressed.xml',zbuf.getvalue())
opener = urllib2.build_opener()
request.add_header('User-Agent', 'A User')
request.add_header('Accept-Encoding', 'gzip, deflate')
request.add_header('Content-Type', 'application/xml')
request.add_header('Content-Encoding', 'gzip')
request.add_header('Content-Length', str(len(zbuf.getvalue())))
## fails here
f = opener.open(request)

compresseddata = f.read()
print 'Compressed response length ', compresseddata.size

compressedstream = StringIO.StringIO(compresseddata)
gzipper = gzip.GzipFile(fileobj=compressedstream)
data = gzipper.read()
print 'Decompressed response length ', len(data)
print data
Many thanks,

Norman Barker

--
Take the DOG out to reply
Jul 18 '05 #1
0 1273

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matthew Thorley | last post by:
Is there a module for unpacking tar files in python? how about bzip2 and gzips? I know I can use the gzip module for gzips but is there anything that can detect what format a file is in and...
5
by: PerryG | last post by:
We have a .NET 1.1 client which is sending a gzipped soap request using HttpWebRequest to an Apache server. The Apache server is using a the 'mod_deflate' server to decompress the incoming...
16
by: Claudio Grondi | last post by:
What started as a simple test if it is better to load uncompressed data directly from the harddisk or load compressed data and uncompress it (Windows XP SP 2, Pentium4 3.0 GHz system with 3 GByte...
9
by: seberino | last post by:
I have been using distuils for a while and was wondering when Python Eggs (new project) is better? So basically Python Eggs precompiles and compresses binaries for you so you just have to load...
2
by: Elric02 | last post by:
I'm currently trying to get access to the Python source code, however whenever I try to extract the files using the latest version of WinZip (version 10) I get the following error "error reading...
10
by: Rocco | last post by:
hi I made the upgrade to python 2.4.3 from 2.4.2. I want to take from google news some atom feeds with a funtion like this import urllib2 def takefeed(url): request=urllib2.Request(url)...
4
by: Aidan | last post by:
Hi, I'm having a bit of trouble with a python script I wrote, though I'm not sure if it's related directly to python, or one of the other software packages... The situation is that I'm trying...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.