By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,629 Members | 1,222 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,629 IT Pros & Developers. It's quick & easy.

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

P: n/a
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(c ookies),

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

Dec 28 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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/pyt...er/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

Dec 28 '06 #2

P: n/a
Ahh that works! thanks a bunch Gabriel

Gabriel Genellina wrote:
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/pyt...er/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
Dec 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.