[Tutor] Beginner: Socket object and packets

Marc Eymard marc_eymard at hotmail.com
Sat Dec 5 08:21:19 EST 2015


Hi tutor,

I am trying to locate the first blank line in the first received packet 
when pinging an internet server using a socket object.

My assumption is there will be a mandatory blank line right after the 
http headers in accordance with the http protocol.

Consider the following:

import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect( ('www.py4inf.com/code/', 80) )
mysock.send('GET http://www.py4inf.com/code/' + ' HTTP/1.0\n\n')
data_str = mysock.recv(700)

My question:

Why is the following statement False when there is an actual blank line 
in the received packet:
     '\n\n' in data

The statement 'any_string in data' works fine with any character except 
the double line drop i.e. '\n\n'.

Attached full script for your consideration.

Thanks in advance for your guidance,
Marc




More information about the Tutor mailing list