FAQ

"livin" <livin@@cox.net> writes:
I need to post form data to an ASP page that looks like this on the page
itself...
<form method='POST'><input src=\icons\devices\coffee-on.gif type='image'
align='absmiddle' width height title='Off'><input type='hidden'
value='Image' name='Action'><input type='hidden' value='hs.ExecX10ByName
"Kitchen Espresso Machine", "Off", 100'></form>
I've been trying this but I get a syntax error...
params = urllib.urlencode({'hidden': 'hs.ExecX10ByName "Kitchen
Espresso Machine", "On", 100'})
urllib.urlopen("http://192.168.1.11:80/hact/kitchen.asp", params)
urlencode doesn't care about the type of the input element (or that
the page is ASP), just the name/value pairs. You want:

params = urllib.urlencode({'Action': 'Image', ...})

The provided HTML doesn't say what the name of the second hidden input
field is. It's not at all clear what should be passed to the server in
this case.

It looks like you tried to break a string across a line boundary, but
that may be your posting software. If you did, then that's what's
generating a syntax error, and a good indication that you should try
reading the tutorial.

<mike
--
Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

Search Discussions

  • Mike Meyer at Dec 28, 2005 at 5:33 am

    "livin" <livin@@cox.net> writes:
    Mike,
    I appreciate the help... I'm a noobie to Python. I know vbscript & jscript
    but nothing else.

    I obviously do not need to submit the images

    my code looks like this but it is not working... any ideas?


    params = urllib.urlencode({'action': 'hs.ExecX10ByName "Kitchen
    Espresso Machine", "Off", 100'})
    urllib.urlopen("http://192.168.1.11:80/hact/kitchen.asp", params)
    No ideas. What does "not working" mean? Do you get a traceback from
    Python? If so, share it - cause what I see here isn't legal Python. Do
    you get an error message from the kitchen.asp form handler? If so,
    ...

    <mike
    --
    Mike Meyer <mwm at mired.org> http://www.mired.org/home/mwm/
    Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
  • Alan Kennedy at Jan 1, 2006 at 5:20 pm
    [livin]
    I'm not a coder really at all (I dabble with vbscript & jscript) but an
    asking for help to get this working.

    I have tried this...

    params = urllib.urlencode({'action': 'hs.ExecX10ByName "Kitchen
    Espresso Machine", "On", 100'})
    urllib.urlopen("http://192.168.1.11:80/hact/kitchen.asp", params)
    You should try to phrase your question so that it is easier for us to
    understand what is going wrong, and thus help you to correct it.

    As Mike already suggested, you have a string that may be spread over two
    lines, which would be illegal python syntax, and which would give a
    SyntaxError if run. You should be sure that this is not the cause of
    your problem before going further.

    The following code should do the same as the above, but not suffer from
    the line breaks problem.

    name_value_pairs = {
    'action': 'hs.ExecX10ByName "Kitchen Espresso Machine", "On", 100'
    }
    params = urllib.urlencode(name_value_pairs)
    urllib.urlopen("http://192.168.1.11:80/hact/kitchen.asp", params)

    BTW, it looks to me like you may be opening up a security hole in your
    application. The following string looks very like a VB function
    invocation: 'hs.ExecX10ByName "Kitchen Espresso Machine", "On", 100'

    Are you executing the contents of form input fields as program code?
    That's highly inadvisable from a security point of view.

    Happy New Year.

    --
    alan kennedy
    ------------------------------------------------------
    email alan: http://xhaus.com/contact/alan
  • Alan Kennedy at Jan 1, 2006 at 8:37 pm
    [livin]
    I have tried the code you suggested and ..
    .. Either way I get this error log...

    File "Q:\python\python23.zlib\urllib.py", line 78, in urlopen
    File "Q:\python\python23.zlib\urllib.py", line 183, in open
    File "Q:\python\python23.zlib\urllib.py", line 297, in open_http
    File "Q:\python\python23.zlib\httplib.py", line 712, in endheaders
    File "Q:\python\python23.zlib\httplib.py", line 597, in _send_output
    File "Q:\python\python23.zlib\httplib.py", line 576, in send
    File "<string>", line 1, in sendall
    IOError
    :
    [Errno socket error] (10057, 'Socket is not connected')
    OK, now we're getting somewhere.

    As you can probably guess from the error message, the socket through
    which urllib is making the request is not connected to the server. We
    have to figure out why.

    That library path is unusual: Q:\python\python23.zlib\httplib.py

    Python supports reading library modules from a zip file, but the
    standard installations generally don't use it, except for Python CE,
    i.e. Python for Microsoft Windows PocketPC/CE/WTF. Is this the platform
    that you're using? If I remember rightly, Python for Pocket Windows
    doesn't support sockets, meaning that urllib wouldn't work on that platform.

    Another thing to establish is whether the URL is working correctly, from
    a client you know works independently from your script above, e.g. an
    ordinary browser. When you submit to your form handling script from an
    ordinary browser, does it work?

    --
    alan kennedy
    ------------------------------------------------------
    email alan: http://xhaus.com/contact/alan


    From livin at Sun Jan 1 21:46:25 2006
    From: livin at (livin)
    Date: Sun, 1 Jan 2006 13:46:25 -0700
    Subject: how-to POST form data to ASP pages?
    References: <bJ1sf.3725$nj1.3317@fed1read07> <861wzzdtp6.fsf@bhuda.mired.org>
    <CwTtf.216$B93.179@fed1read07> <9bUtf.3962$j7.88355@news.indigo.ie>
    <S8Wtf.225$B93.98@fed1read07> <E4Xtf.3968$j7.88027@news.indigo.ie>
    Message-ID: <KbXtf.228$B93.117@fed1read07>

    The library is the PC version of 2.3 --- I have done some more testing.

    I simplified my .py to only 2 lines...

    import urllib
    urllib.urlopen('http://192.168.1.11', urllib.urlencode({'control_device':
    'Kitchen Lights=off'}))

    I get this error...

    File "Q:\python\python23.zlib\urllib.py", line 78, in urlopen
    File "Q:\python\python23.zlib\urllib.py", line 183, in open
    File "Q:\python\python23.zlib\urllib.py", line 297, in open_http
    File "Q:\python\python23.zlib\httplib.py", line 712, in endheaders
    File "Q:\python\python23.zlib\httplib.py", line 597, in _send_output
    File "Q:\python\python23.zlib\httplib.py", line 564, in send
    File "Q:\python\python23.zlib\httplib.py", line 548, in connect
    IOError
    :
    [Errno socket error] (10060, 'Operation timed out')

    I've taken the commands I'm using from working HTTP & ASP pages.

    Here's actual code from an HTML page I'm using for the same device I'm
    trying in my .PY...

    <form method="post">
    <td nowrap class="tableroweven">
    <a name="bm83274"></a>
    <input type="hidden" name="bookmark" value="83274">
    <input type="hidden" name="ref_page" value="stat">
    <input type="hidden" name="control_device" value="Kitchen Lights">
    <input class="formbutton" type="submit" name="action_on" value="On">
    <input class="formbutton" type="submit" name="action_off" value="Off">
    <select class="formdropdown" name="selectdim" SIZE="1"
    onchange="SubmitForm(this)">
    <option selected value="0">0%</option>
    <option value="10">10%</option>
    <option value="20">20%</option>
    <option value="30">30%</option>
    <option value="40">40%</option>
    <option value="50">50%</option>
    <option value="60">60%</option>
    <option value="70">70%</option>
    <option value="80">80%</option>
    <option value="90">90%</option>
    <option value="100">100%</option>
    </select>
    </td></form>




    "Alan Kennedy" <alanmk at hotmail.com> wrote in message
    news:E4Xtf.3968$j7.88027 at news.indigo.ie...
    [livin]
    I have tried the code you suggested and .. .. Either way I get this error
    log...

    File "Q:\python\python23.zlib\urllib.py", line 78, in urlopen
    File "Q:\python\python23.zlib\urllib.py", line 183, in open
    File "Q:\python\python23.zlib\urllib.py", line 297, in open_http
    File "Q:\python\python23.zlib\httplib.py", line 712, in endheaders
    File "Q:\python\python23.zlib\httplib.py", line 597, in _send_output
    File "Q:\python\python23.zlib\httplib.py", line 576, in send
    File "<string>", line 1, in sendall
    IOError
    :
    [Errno socket error] (10057, 'Socket is not connected')
    OK, now we're getting somewhere.

    As you can probably guess from the error message, the socket through which
    urllib is making the request is not connected to the server. We have to
    figure out why.

    That library path is unusual: Q:\python\python23.zlib\httplib.py

    Python supports reading library modules from a zip file, but the standard
    installations generally don't use it, except for Python CE, i.e. Python
    for Microsoft Windows PocketPC/CE/WTF. Is this the platform that you're
    using? If I remember rightly, Python for Pocket Windows doesn't support
    sockets, meaning that urllib wouldn't work on that platform.

    Another thing to establish is whether the URL is working correctly, from a
    client you know works independently from your script above, e.g. an
    ordinary browser. When you submit to your form handling script from an
    ordinary browser, does it work?

    --
    alan kennedy
    ------------------------------------------------------
    email alan: http://xhaus.com/contact/alan

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 27, '05 at 4:56a
activeJan 1, '06 at 8:37p
posts4
users2
websitepython.org

2 users in discussion

Mike Meyer: 2 posts Alan Kennedy: 2 posts

People

Translate

site design / logo © 2022 Grokbase