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

Gabriel Genellina gagsl-py at yahoo.com.ar
Wed Dec 27 22:56:30 EST 2006


At Thursday 28/12/2006 00:11, flamesrock wrote:


>The problem is that, while the login opener works, the
>update_city_params opener does not. It returns the following error:
>flamesrock at tux ~/send $ python send.py
>Traceback (most recent call last):
>   File "send.py", line 14, in ?
>     opener.open(url, update_city_params)
>   File "/usr/lib/python2.4/urllib2.py", line 356, in open
>     req = meth(req)
>   File "/home/flamesrock/asdf/MultipartPostHandler.py", line 75, in
>http_request
>     boundary, data = self.multipart_encode(v_vars, v_files)
>   File "/home/flamesrock/asdf/MultipartPostHandler.py", line 87, in
>multipart_encode
>     boundary = mimetools.choose_boundary()
>   File "/usr/lib/python2.4/mimetools.py", line 130, in choose_boundary
>     hostid = socket.gethostbyname(socket.gethostname())
>socket.gaierror: (-2, 'Name or service not known')

MultipartPostHandler uses mimetools.choose_boundary; it relies on 
socket.gethostbyname returning a sensible result for your machine. 
But sometimes it fails: 
http://mail.python.org/pipermail/python-list/2003-October/232722.html
It may be a bug in Python, or in the sockets implementation, or 
somewhere. Anyway, choose_boundary() should be robust enough to catch 
the possible exception and act accordingly, I think.

In the meantime, you may put this near the top of your script:

mimetools._prefix = "some-random-string-you-like"


-- 
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 




More information about the Python-list mailing list