On 10月19日, 下午11时05分, "Gabriel Genellina" <gagsl-...@yahoo.com.ar> wrote: > En Mon, 19 Oct 2009 05:44:14 -0200, 星星 <starstarstar...@gmail.com> > escribió: > > > my email smtp server hostname can be parsed to 5 ips, for example: > > ****************************************************************** > > my email smtp server hostname: email-my.local.com > > ips through dns parse: > > 1.1.1.1 > > 1.1.1.12 > > 1.1.13.1 > > 1.1.1.14 > > 1.1.1.15 > > ****************************************************************** > > > but when i send mail using smtplib, i was always using one ip, no > > dns re-resolve happened, (for example: only use 1.1.1.12). I checked > > smtplib src code, but i can't find anything strange; > > smtplib does not issue a dns query for a MX record, if that is what you > were expecting. In fact, the Python standard library does not contain any > module for DNS handling. > > > for i in range(1000): > > server = smtplib.SMTP(host) > > Here, `host` is used directly -- whatever address gethostbyname returns. > If you want load balancing among the 5 addresses above, you'll have to do > it yourself: > host = random.choice(list_of_addresses) > > If you don't want to hardcode the addresses, there are a few libraries > that perform DNS queries in PyPI. > > -- > Gabriel Genellina
thanks very much! I tried your suggestion and it worked! But I still wonder why gethostbyname returns the same address all the time(maybe 50000 times). -- http://mail.python.org/mailman/listinfo/python-list