All, 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. <CODE> binvalues = array.array('f') rawData = urllib2.urlopen("http://dsd1u:7003/GRID:U:NOGAPS:2005041800:global_360x181:a ir_temp:ht_sfc:00020000:00000000:fcst_ops:0240") binvalues.fromstring(rawData.read(4)) # 4 byte float binvalues.byteswap() print binvalues </CODE> -----Original Message----- From: Kent Johnson Cc: tutor@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 tech > guys are around so I am hoping you might be able to shed some light on what > 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? Kent > > 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. > > http://dsd1u:7003/GRID:U:WW3_GLOBAL:2005041512:global_360x181:max_wav_ht :sur > 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 that > since f (the object) exists the call to the web service worked. Now I need > 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 = > > urllib.urlopen("http://dsd1u:7003/GRID:U:WW3_GLOBAL:2005041800:global_36 0x18 > 1:max_wav_ht:surface:00000000:00000000:fcst_ops:0240") > >>>>f.info() > > <httplib.HTTPMessage instance at 0xb9255f6c> > >>>>f.readlines() > > > I tried read(), readLines() and some other stuff using scipy and Numeric. > > 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 says > 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@python.org > http://mail.python.org/mailman/listinfo/tutor > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor