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

F

flamesrock

Hi,

Basically, I'm trying to send a multipart form to a server using some
code from aspn.. here it is:
MultipartPostHandler: http://pastie.caboo.se/29833

import MultipartPostHandler, urllib2, cookielib

cookies = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookies),

MultipartPostHandler.MultipartPostHandler)


login_params = { "user[login]" : "guest", "user[password]" : "guest"}
url="http://localhost:2056/user/login?"
opener.open(url, login_params)

update_city_params = { "user[login]" : "guest", "user[password]" :
"guest" , "city[cityfile]" : open("elephantia.sc4","rb"), "region[id]"
: "2"}
url="http://localhost:2056/simnet/update_city?"
opener.open(url, update_city_params)


The problem is that, while the login opener works, the
update_city_params opener does not. It returns the following error:
flamesrock@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')


I simply do not know where to begin. Anyone have an idea what the error
means? :/

-Thanks in Advance
flamesrock
 
G

Gabriel Genellina

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

flamesrock

Ahh that works! thanks a bunch Gabriel

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



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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top