473,556 Members | 2,558 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python compressed URL post


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.HTTPCon nection.debugle vel = 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.String IO()
zfile = gzip.GzipFile(m ode = 'wb', fileobj = zbuf, compresslevel = 9)
zfile.write(buf );
print 'compressed request file size is ', len(zbuf.getval ue())
request =
urllib2.Request ('http://localhost/cocoon/compressed.xml' ,zbuf.getvalue( ))
opener = urllib2.build_o pener()
request.add_hea der('User-Agent', 'A User')
request.add_hea der('Accept-Encoding', 'gzip, deflate')
request.add_hea der('Content-Type', 'application/xml')
request.add_hea der('Content-Encoding', 'gzip')
request.add_hea der('Content-Length', str(len(zbuf.ge tvalue())))
## fails here
f = opener.open(req uest)

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

compressedstrea m = StringIO.String IO(compressedda ta)
gzipper = gzip.GzipFile(f ileobj=compress edstream)
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 1288

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

Similar topics

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 decopress and unpack it using the other methods? thanks -Matthew
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 message, and to also compress the response (GZIP). The mod_deflate filter requires the 'Content-Length' header contained within the incoming request to...
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 RAM) seems to show that none of the in Python available compression libraries really works for large sized (i.e. 500 MByte) strings. Test the...
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 it to run your app? Chris
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 however after processing 0 entries
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) request.add_header('User-Agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT') opener = urllib2.build_opener()
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 to create a system backup script that creates an image of the system, filters the output though gzip, and then uploads the data (via ftp) to a...
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.