Explorar el Código

- Better error message when HTTP server cannot reverse-resolve a
hostname to an IP address. Previous behavior: show a socket
error. Current behavior: spit out a suggestion to stdout.

Chris McDonough hace 14 años
padre
commit
7a516a2603
Se han modificado 2 ficheros con 16 adiciones y 1 borrados
  1. 6 0
      CHANGES.txt
  2. 10 1
      src/supervisor/http.py

+ 6 - 0
CHANGES.txt

@@ -1,3 +1,9 @@
+Next release
+
+  - Better error message when HTTP server cannot reverse-resolve a
+    hostname to an IP address.  Previous behavior: show a socket
+    error.  Current behavior: spit out a suggestion to stdout.
+
 3.0a9 (2010-08-13)
 
   - Use rich comparison methods rather than __cmp__ to sort process

+ 10 - 1
src/supervisor/http.py

@@ -547,7 +547,16 @@ class supervisor_af_inet_http_server(supervisor_http_server):
         host, port = self.socket.getsockname()
         if not ip:
             self.log_info('Computing default hostname', 'warning')
-            ip = socket.gethostbyname (socket.gethostname())
+            hostname = socket.gethostname()
+            try:
+                ip = socket.gethostbyname(hostname)
+            except socket.error:
+                raise ValueError(
+                    'Could not determine IP address for hostname %s, '
+                    'please try setting an explicit IP address in the "port" '
+                    'setting of your [inet_http_server] section.  For example, '
+                    'instead of "port = 9001", try "port = 127.0.0.1:9001."'
+                    % hostname)
         try:
             self.server_name = socket.gethostbyaddr (ip)[0]
         except socket.error: