472,348 Members | 1,224 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,348 software developers and data experts.

httplib and socket.getaddrinfo

I noticed the following lines from the connect() method of the
HTTPConnection class within httplib:

for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res

This led me to the docs that describe the socket.getaddrinfo() method:

http://www.python.org/doc/2.4.1/lib/module-socket.html

Which leads me to these questions:
1) Is it correct to infer from the "Resolves the host/port argument,
into a sequence of 5-tuples that contain all the necessary argument for
the sockets manipulation" description in the docs (in particular the
reference to 'sequence of 5-tuples') that a single host/port
combination may be associated with multiple sets of address
information?

2) In the very limited applications on which I've used
socket.getaddrinfo(), each a host/port combination that my application
passes to socket.getaddrinfo() has always returned a 1-entry list where
the list is a 5-tuple, in other words, each host/port combination has
always been associated with one set of address information. Can
someone point me to a host/port combination that, when passed to
socket.getaddrinfo() will result in socket.getaddrinfo() returning a
list of 1 entry, where each entry is a 5-tuple?

Thank you.

Dec 23 '06 #1
1 3082
At Saturday 23/12/2006 04:21, mi************@yahoo.com wrote:
>I noticed the following lines from the connect() method of the
HTTPConnection class within httplib:

for res in socket.getaddrinfo(self.host, self.port, 0,
socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res

This led me to the docs that describe the socket.getaddrinfo() method:

http://www.python.org/doc/2.4.1/lib/module-socket.html

Which leads me to these questions:
1) Is it correct to infer from the "Resolves the host/port argument,
into a sequence of 5-tuples that contain all the necessary argument for
the sockets manipulation" description in the docs (in particular the
reference to 'sequence of 5-tuples') that a single host/port
combination may be associated with multiple sets of address
information?
Yes. By example, multiple addresses for the same service are used for
load balancing. Or an IPv4 address plus an IPv6 address.
>2) In the very limited applications on which I've used
socket.getaddrinfo(), each a host/port combination that my application
passes to socket.getaddrinfo() has always returned a 1-entry list where
the list is a 5-tuple, in other words, each host/port combination has
always been associated with one set of address information. Can
someone point me to a host/port combination that, when passed to
socket.getaddrinfo() will result in socket.getaddrinfo() returning a
list of 1 entry, where each entry is a 5-tuple?
Try to relax your restrictions.

import socket
host = 'www.microsoft.com'
port = 'ftp'
for res in socket.getaddrinfo(host, port):
print res

Got 8 results:
(2, 1, 0, '', ('207.46.198.30', 21))
(2, 1, 0, '', ('207.46.198.60', 21))
(2, 1, 0, '', ('207.46.199.30', 21))
(2, 1, 0, '', ('207.46.225.60', 21))
(2, 1, 0, '', ('207.46.19.30', 21))
(2, 1, 0, '', ('207.46.19.60', 21))
(2, 1, 0, '', ('207.46.20.30', 21))
(2, 1, 0, '', ('207.46.20.60', 21))
--
Gabriel Genellina
Softlab SRL


__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas

Dec 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin Fuzzey | last post by:
I am using xmlrpclib (based on httplib) in Python 2.3 on Mandrake Linux. When my client attempts to connect to a server using a...
0
by: Bernhard Schmidt | last post by:
Hello, sorry for bothering, I'm not a programmer and I don't do much python, I'm more a networking guy trying to get his favourite linux...
0
by: Robert | last post by:
did you solve this problem? It seems to be still present here with py2.3.5. Robert -- From: Manish Jethani <manish.j@gmx.net> User-Agent:...
4
by: Patrick Altman | last post by:
I am attempting to use a HEAD request against Amazon S3 to check whether a file exists or not and if it does parse the md5 hash from the ETag in...
3
by: Thomas Dybdahl Ahle | last post by:
Hi, I'm writing an application that connects to the internet. Something like this: for res in socket.getaddrinfo(host, port, 0,...
2
by: John Nagle | last post by:
Here's a strange little bug. "socket.getaddrinfo" blows up if given a bad domain name containing ".." in Unicode. The same string in ASCII...
3
by: rhXX | last post by:
hi all, i'm using this tutorial example import httplib h = httplib.HTTP("www.python.org") h.putrequest('GET','/index.html')...
0
by: Marco Bizzarri | last post by:
On Wed, Sep 3, 2008 at 11:06 AM, jorma kala <jjkk73@gmail.comwrote: localhost is not resolved to 127.0.0.1 on your machine. Try changing it...
7
by: Adam01 | last post by:
Im using cygwin to test the code of a server I am writing. I've included sys/types.h, sys/socket.h, netdb.h, and arpa/inet.h. And this is the...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.