raw binary data and httplib 
Author Message
 raw binary data and httplib


i'm trying to program a specialized web proxy. I first tried
urllib.urlopen to get data via HTTP from a web server. Everything went
ok with normal text/html data. But I have to load binary data with a
certain MIME-type via HTTP. So I started using httplib hoping that
there's no special character handling in it.

This doesn't work even for text/html data:

  h = httplib.HTTP(servername)
  h.putrequest('GET', filename+'?'+url_query_string)
  h.putheader('Accept', content_type)
  errcode, errmsg, headers = h.getreply()

  print 'Content-type: '+headers.gettype()+'\n'
  f = h.getfile()
  data = f.read()

The URL is retrieved and I can see the amount of data transferred in the
Apache server logs. The received content-type in headers.gettype() is
right. But it seems that the first few hundred bytes of the data are

I also tried os.read(f.fileno(),n) for reading but same effect. The data
is cut.

It works for text/* if i'm switching to readline-method:

  f = h.getfile()
  data = f.readline()
  while data
    data = f.readline()

Can somebody tell me how the get binary data with the httplib?
Where should I have a look in httplib?

Ciao, Michael.

Mon, 30 Oct 2000 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. newbie:displaying raw binary data

2. Using DEC Fortran to read raw binary data?

3. Tkinter: passing raw binary data back and forth

4. Extract data from radius's raw data

5. PyObject *data - access to raw data?

6. Raw binary image from a PE executable.

7. Writing sequential raw binary

8. re-opening stdin in raw (binary) mode?

9. Reading binary file, convert raw bytes

10. Working with raw binary digits.

11. Reading a binary file / writing binary data to a file

12. Raw data from the Aus Stocks


Powered by phpBB® Forum Software