FAQ
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 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')


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

-Thanks in Advance
flamesrock

Search Discussions

  • Gabriel Genellina at Dec 28, 2006 at 3:56 am
    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
  • Gabriel Genellina at Dec 28, 2006 at 4:29 am

    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.
    The underlying bug was already reported and solved:
    http://sourceforge.net/tracker/index.php?funcÞtail&aid50170&group_idT70&atid5470
    Should work on Python 2.4.4 and later.


    --
    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
  • Flamesrock at Dec 28, 2006 at 4:33 am
    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 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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 28, '06 at 3:11a
activeDec 28, '06 at 4:33a
posts4
users2
websitepython.org

2 users in discussion

Flamesrock: 2 posts Gabriel Genellina: 2 posts

People

Translate

site design / logo © 2021 Grokbase