Spoiler to Python Challenge (help!!!)

Ian Vincent i_vincent at hotmail.com
Tue Sep 27 15:32:22 CEST 2005

Damn this is annoying me.

I have a webpage with a BZ2 compressed text embedded in it looking like:

'BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M

Now, if I simply copy and paste this into Python and decompress it - it 
works a treat.

However, I want to read the file containing this data, extract the data 
and decompress it and this for some reason does not work.

I am doing the following (excuse the probably very long handed way of 
doing it):

file = urllib.urlopen(url, proxies=proxies)
line = file.readlines()
line = line[20:]
line = line[:-1]
user = line[0]
password = line[1]
user = user[5:]
user = user[:-2]
user = str(user)
password = password[5:]
password = password[:-2]

This gives me a user string of:

BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M

But if I put this into the decompression function, I get a error of 
'IOError: invalid data stream'.

I know it is the escape characters but how do I get these to be correctly 
converted into a string compatible with bz2.decompress()?

More information about the Python-list mailing list