PDA

View Full Version : python urllib f.read() giving me trbl



jerry01
July 12th, 2011, 04:55 PM
i've got a problem with python 3.1 using urllib

i can't seem to get the returned data into a string. i need to have something i can manipulate. could someone tell me how to go from "f.read()" to data or an array?


f = urllib.request.urlopen(urlstr)
print(f.read(5000))
data=f.read()
print(">>>>>"+str(data))
b'<html>\r\n/var/web/servlet.ksh null 53.104891 \r\n</html>\r\n'
>>>>>b''

it's probably a basic question but i've already wasted a lot of time...
many thanks

Bachstelze
July 12th, 2011, 05:36 PM
For starters, why are you calling read() twice? It probably does not do what you think.

jerry01
July 12th, 2011, 06:06 PM
found my own solution

as follows if anyone is interested...


f = urllib.request.urlopen(urlstr)
by= bytearray(f.read(100))
data=by.decode("ascii")