[Pythonmac-SIG] urllib problem

Tattoo Mabonzo K. tmk@easynet.be
Thu, 28 Dec 2000 15:33:21 +0100


Yo,

I got caught by that one already.

But as always, Jack was quick to point to the solution. Please below. I =
copy-paste=20
his answer.

--- cut

Hi,
that's not broken, it's only strange. There is absolutely no guarantee =
how=20
much a read() on a socket will return. The correct way to read all data =
is to=20
do
  x =3D urllib.urlopen(....)
  alldata =3D ''
  while 1:
    next =3D x.read()
    if not next: break
    alldata =3D alldata + next

However, as it often happens on unix that you get all data in one read =
call,=20
and sometimes on MacOS too, it's easy to think that read should return=20=

everything.

Note that read() on files does guarantee that it returns all data.

--- cut

On Wednesday, December 27, 2000, at 12:11 AM, Moroo Jun wrote:

> I tried to run follow program, Python 1.5.2c get all text from web =
site,=20
> but Python 2.0 doesn't.=20
> In Solaris 2.6, the same program can get all text from web site both =
with=20
> Python 1.5.2 and Python 2.0.=20
> =20
> --- Begin ---=20
> import urllib=20
> =20
> a=3Durllib.urlopen("http://www.yahoo.co.jp/")=20
> d=3Da.read()=20
> f=3Dopen("yahoo.html","wb")=20
> f.write(d)=20
> f.close()=20
> a.close()=20
> --- End ---=20
> =20
> I tried them on:=20
> Powerbook G3/333 OS 8.6=20
> PowerMacintosh 9600/233 OS 9.0=20
> =20
> -- =20
> moroo@jp.fujitsu.co.jp=20
> Fujitsu Laboratories LTD.=20
> =20
> _______________________________________________=20
> Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org=20
> http://www.python.org/mailman/listinfo/pythonmac-sig=20
> =20
> =20