[Tutor] requests/responses from urllib2

Kent Johnson kent37 at tds.net
Tue Aug 12 14:45:01 CEST 2008

On Tue, Aug 12, 2008 at 7:27 AM, Eric Abrahamsen
<eric at ericabrahamsen.net> wrote:
> On Aug 11, 2008, at 6:54 PM, Kent Johnson wrote:
>> I'm not sure if you want to see the traffic coming in from your users,
>> or the traffic from your server to the third-party server. I don't
>> know what kind of interaction you want, either.
> I'd like to be able to see the response coming back from the third-party
> server, and have lighttpd check its headers and either intercept it or allow
> it back into the framework. Say if it's got a text content-type then let it
> in to the framework, and if it's got an image content-type then ignore it or
> throw it away. Rephrasing it this way makes it sound pretty unlikely. I
> guess what I wanted was a better sense of how urllib2 uses a socket to make
> the request, and how the response, on its way back to my server, finds that
> socket. I thought that if the socket file was something that hung around
> between requests, I might be able to configure lighttpd to 'listen in' on
> that socket, and grab the response if it met certain criteria. But if that
> were possible then urllib2 would raise an error, right?

lighttpd will not see the traffic to the third-party server; the tp
server is not making a request of lighttpd; your code is making a
request of it. The response comes back on the same socket that was
opened by the request; if you want to know how they match up you will
have to learn about TCP/IP which is the underlying network protocol.
This might help:

If you want to filter the response according to the headers, you can
do that in your code. The response object returned by urllib2 includes
an info() method that gives access to the response headers.


PS Please Reply All to reply to the list.

More information about the Tutor mailing list