Because the project requires a lot of data, even though databases released by some research centers on the Internet are charged, it is a luxury for me to have three employees.
(A human face recognition database requires 1000 million USD! WTF !)
Try to develop a search tool by yourself...
First test a small socket function (very small, the experts will pass ...)
[Python] # testint of sending infomation to www.2cto.com
Import sys, socket, time
Host = sys. argv [1]
Xport = sys. argv [2]
Filename = sys. argv [3]
Print ('getting socket ...')
Try:
S = socket. socket (socket. AF_INET, socket. SOCK_STREAM)
Failed t socket. error, e:
Print ('here is a error: % s') % e
Sys. exit (1)
Print ('done ')
Print ('getting socket port ')
Try:
Port = int (xport)
Failed t ValueError:
Try:
Port = socket. getprotobyname (xport, 'tcp ')
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
Print ('done ')
Print ('ing ing the host ')
Try:
S. connect (host, port ))
Handle t socket. gaierror, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
Print ('done ')
Print ('sleeping ...')
Time. sleep (3)
Print ('ing ing ...')
Try:
S. sendall ('get % s HTTP/1.0 \ r \ n \ r \ n' % filename)
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
Try:
S. shutdown (1)
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
While True:
Try:
Buf = s. recv (64)
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
If not len (buf ):
Break
Sys. stdout. write (buf)
# Testint of sending infomation to www.2cto.com
Import sys, socket, time
Host = sys. argv [1]
Xport = sys. argv [2]
Filename = sys. argv [3]
Print ('getting socket ...')
Try:
S = socket. socket (socket. AF_INET, socket. SOCK_STREAM)
Failed t socket. error, e:
Print ('here is a error: % s') % e
Sys. exit (1)
Print ('done ')
Print ('getting socket port ')
Try:
Port = int (xport)
Failed t ValueError:
Try:
Port = socket. getprotobyname (xport, 'tcp ')
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
Print ('done ')
Print ('ing ing the host ')
Try:
S. connect (host, port ))
Handle t socket. gaierror, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
Print ('done ')
Print ('sleeping ...')
Time. sleep (3)
Print ('ing ing ...')
Try:
S. sendall ('get % s HTTP/1.0 \ r \ n \ r \ n' % filename)
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
Try:
S. shutdown (1)
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
While True:
Try:
Buf = s. recv (64)
Failed t socket. error, e:
Print ('here is an error happened: % s') % e
Sys. exit (1)
If not len (buf ):
Break
Sys. stdout. write (buf)
The socket module of Python (version 2.6 and version 3.2 have not been tried yet, and it is estimated that it is similar) defines four possible errors:
1 related to general IO and communication problems: socket. error
2. query address information: socket. gaierror
3 related to other address errors: socket. herror
4. It is related to the processing timeout after settimeout () is called on a socket: socket. timeout
The above code has a major problem, that is, the socket is not closed, because the shutdown function of the socket module needs to be tested (because the shutdown function may cause some problems if the program is improperly designed ), add this code segment.
[Python] try:
S. shutdown (1)
Failed t socket. error, e:
Print ('here is an error: % s') % e
Sys. exit (1)
Try:
S. shutdown (1)
Failed t socket. error, e:
Print ('here is an error: % s') % e
Sys. exit (1)
Lol
From the column of FishinLab