[Tutor] requests/responses from urllib2

Alan Gauld alan.gauld at btinternet.com
Mon Aug 11 10:49:28 CEST 2008

"Eric Abrahamsen" <eric at ericabrahamsen.net> wrote

> that traffic go in and out of my server machine? The python docs say 
> that urllib2 requires the socket library to work, so I assume it's a 
> socket of some sort, but I don't really understand how that socket 
> is  addressed, from the point of view of the third-party server that 
> is  receiving my urllib2 request, and returning the response.

Virtually all network comms is over sockets. Your web browser
uses sockets every time it connects to a web server. Your web
server is using sockets to receive those requests.

The urllib implementation has to use the Python socket
module so there is a dependency but thats just what you'd expect.
It has to talk to a socket somehow and if it didn't use the socket
library directly it would either use a higher level library that in
turn used socket, or else it would have to implement sockets
itself at the C level.

> it appear to be coming from? If my web server (lighttpd in this 
> case)  is set to listen on a particular port, is there any way that 
> it can  'see' that traffic and interact with it, or is it purely 
> between the  python library and the outside world?

Your web server likely listens on port 80.
The urllib will send to port 80 by default.

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list