Re: Socket - gaierror



In article <1188260349.031088.69010@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
half.italian@xxxxxxxxx writes:
On Aug 27, 4:22 pm, s...@xxxxxxxxxxxxxxxxx (Douglas Wells) wrote:
In article <1188244050.029920.314...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,

half.ital...@xxxxxxxxx writes:
On Aug 27, 12:32 pm, Larry Bates <larry.ba...@xxxxxxxxxxx> wrote:

Changing it to IP gives me the same exact error...

File "bin/prgram.py", line 123, in notify
smtp = smtplib.SMTP("XXX.XXX.XXX.XXX")

File "/usr/lib/python2.4/smtplib.py", line 255, in __init__
addr = socket.gethostbyname(socket.gethostname())

gaierror: (-2, 'Name or service not known')

~Sean

Note that the lookup is of your *local* system name
(socket.gethostname()). I suspect that the name of your client
system (the one running the python script) is not registered in
DNS.

Try ping'ing your own system and see if that resolves in DNS. In
UNIX/Linux you can use the hostname command; in any system you can
write a python script to print the result of socket.gethostname().

- dmw

I found a solution...but still not sure why that happened.

root@00:17:08:5E:EF:0F:/usr/local/sw/program/bin# hostname
00:17:08:5E:EF:0F
root@00:17:08:5E:EF:0F:/usr/local/sw/program/bin# ping 00:17:08:5E:EF:0F
ping: unknown host 00:17:08:5E:EF:0F

socket.gethostname()
'00:17:08:5E:EF:0F'

Workaround: pass the 'local_hostname' arg to the smtplib.SMTP() call
with "localhost"

ie smtp.SMTP("some.computer", local_hostname="localhost")

This is just overriding the socket.gethostname() call entirely.

Did a bit of testing with the /etc/hosts file, and even with an entry
to the hostname it can't resolve the ip.
The problem is the name "00:17:08:5E:EF:0F" PS. I didn't choose to
set the hostname that way.

~Sean

That would be a reasonable workaround. The process of sending
e-mail via SMTP could need the local host name for at least two
uses: 1) the SMTP initial connection (RFC 2821) requires the
client to identify itself (provide its host name); 2) the mail
headers (RFC 2822) should include a return address, which probably
defaults to using your user name at your client host name.

The hostname of your system (00:17:08:5E:EF:0F) is silly when used
with SMTP. Your system administrator is either ill-informed or is
actively trying to prevent users from using their systems as
servers. It has the form of an IPv6 numeric host address.

Given the pathnames in your command interchange, you have a UNIX,
Linux, or UNIX-like system. According to the Linux and UNIX standards:

- If your system is IPv6-capable, the use of such a name with
gethostbyname invokes "unspecified behavior." First, the function
is not defined to work with such "numeric" identifiers. Second,
it is not guaranteed to work with non-IPv4 names, and probably
can't be registered in pre-i18n DNS data bases.

- Even if your system is not IPv6-capable, such a host name is going
to confuse many other systems that would be IPv6-capable and attempt
to resolve the odd-ball name that your system provides.

- Even if that worked, you're providing an IPv6 name form in
conjunction with an IPv4 protocol (at least when you explicitly
provide the IP address as a dotted-quad).

- dmw

--
.. Douglas Wells . Connection Technologies .
.. Internet: -sp9804- -at - contek.com- .
.



Relevant Pages

  • Re: Mldonkey hostname ??
    ... Host case not found: 3 ... local LAN IP addresses aren't going to resolve externally. ... peer-to-peer would have a hostname that could be externally resolved, ... to the correct IP address of the host running mldonkey". ...
    (Fedora)
  • Re: Mldonkey hostname ??
    ... Host case not found: 3 ... local LAN IP addresses aren't going to resolve externally. ... peer-to-peer would have a hostname that could be externally resolved, ... to the correct IP address of the host running mldonkey". ...
    (Fedora)
  • Re: how to get remote host name
    ... it means the IP address you provided has no associated host name ... if the remote connection gave you the ability to query its name via the ... I had used gethostbyaddrto retreive the hostname of the other side. ... If the server and the client in the same subnetwork everything work ...
    (microsoft.public.vc.mfc)
  • Re: What is the difference between "No address associated with name" and "Unknown host"
    ... ping: cannot resolve accounts.eirtrade.ie: No address associated with name ... ping: cannot resolve accounts.eirtrade.i: Unknown host ... Because the domain name server cannot be found, it is not possible to tell the IP address of the given hostname. ...
    (freebsd-questions)
  • Re: server side socket program hangs
    ... > my initial program was to take host value as '' ... with my client program. ... You keep saying that the programs 'hang', ... Thus it will only accept connections specific to the hostname and ...
    (comp.lang.python)