FW: [Tutor] Trying to d0 HTTP GET

Ertl, John john.ertl at fnmoc.navy.mil
Tue Apr 19 18:55:02 CEST 2005


I have figured out a bit more.  I can get the binary values from the service
but I think they come back as a single string.  How do I read that into an
array?  The code below will read the first number into the array and print
it out but how would I read the whole thing into an array...I would like to
skip the step of putting the raw binary numbers into a variable and instead
read it directly into the binvalues array.

I have tried things like  binvalues.read(rawData.read(4,size of array)) and
a few other things but none of them work.  I was hoping for a fromstream but
no luck no that either.
Thanks for any help.
binvalues = array.array('f')

rawData =

binvalues.fromstring(rawData.read(4))  # 4 byte float


print binvalues


-----Original Message-----
From: Kent Johnson
Cc: tutor at python.org
Sent: 4/18/05 1:10 PM
Subject: Re: [Tutor] Trying to d0 HTTP GET

Ertl, John wrote:
> All,
> I am trying to get some binary data from a web service.  None of the
> guys are around so I am hoping you might be able to shed some light on
> might be happening.

I would think that
f = urllib.urlopen(...)
data = f.read()

would work. You could try urllib2.urlopen() and see if it is any better.

How big is the data you are expecting?


> Here is part of the email that explained what I needed to do.
> ----- clip ---
> If you can do an http "get" from Python, you'll be set.
> face:00000000:00000000:fcst_ops:0480
> It returns an http header like the following (if the grid exists),
> followed by the grid data in big-endian, IEEE format.
>          "HTTP/1.1 200 OK\r\n"
>          "Server: ISIS/4.0\r\n"
>          "Content-type: application/x-grid\r\n"
>          "Content-length: 261234\r\n\r\n"
> ----- end-----
> The grid data is in Binary.  How would I get to this?  I would imagine
> since f (the object) exists the call to the web service worked. Now I
> to read the grid...eventually I need to put it into a Numeric array
but not
> sure how to get just the grid from "f".
> As a simple starting point I tried. 
>>>>import urllib
>>>>f =
> 1:max_wav_ht:surface:00000000:00000000:fcst_ops:0240")
> <httplib.HTTPMessage instance at 0xb9255f6c>
> I tried read(), readLines() and some other stuff using scipy and
> The prompt has moved to the next line but nothing else has happened
for 30
> min or so (I have tried several times).  When I try to close IDLE it
> the program is still running.  How should I be getting this data is it
> trying to read the binary and that is why it is stalled? 
> Thanks,
> John Ertl
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list