newbie problem: use socke lib to retrieve one web page:

read-the-signature at send-spam-to-dev-null.com read-the-signature at send-spam-to-dev-null.com
Thu Sep 5 13:20:45 CEST 2002


koko <kokohh at hotmail.com> wrote:
> I write this to retrieve one web page using socket lib.
> [snip: code]
> s.connect((HOST,PORT))
> s.send(m)
> data=s.recv(4096)
> print data
> s.close()
> 
> -----------
> But I retrieved nothing and the program stuck.


Your code probably is _too quick_ for the server. That is, you tried to
read data while the server was still busy processing. You could "sleep" a
little, before reading. Oh yeah, are you sure that 

    data = s.recv(4096)

will _always_ give you all of the data? You might want to take a look at
asyncore [1] which provides a nicer way to handle these situations. I'm not
sure, but I expect that the Python cookbook [2] also has some interesting
things to say about this topic.

    Good luck!

        Bas

[1]   http://www.python.org/doc/current/lib/module-asyncore.html
[2]   http://aspn.activestate.com/ASPN/Python/Cookbook/

-- 
b a s {dot} v a n g i l s {at} c s {dot} k u n {dot} n l
BOFH excuse #63:
not properly grounded, please bury computer



More information about the Python-list mailing list