Form Value Won't Post/Submit

Discussion in 'Python' started by SuperMetroid, Oct 12, 2009.

  1. SuperMetroid

    SuperMetroid Guest

    The html code of the form, and my code are below. I can't get the
    value to post/submit.. instead I get an error. Can anyone help?

    HTML Code of Form:
    <form method='post' autocomplete='off'>
    <input type='hidden' name='action' value='grant-revoke' />
    <input type='hidden' name='creator_badge_index' value='1' />

    <input type='hidden' name='token'
    value='92dcd92a8bc16f73f330d118ae1ed891' />
    <input type='hidden' name='do-grant' value='1' />
    <div id='grant-div'><span class='label'>Grant badge: </span><input
    type='text' id='grant-userid' name='grant-userid' value='userid /
    avatar name' /><input type='submit' value='Grant!' /></div>
    </form>

    My Code:
    opener = urllib.request.build_opener()
    cj = http.cookiejar.MozillaCookieJar()
    cj.load('C:/Users/Alison/Documents/moz_cookies.txt')
    opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor
    (cj))

    params = urllib.parse.urlencode({'grant-userid' : 'Guest_xLolKittyx'})
    form = urllib.request.OpenerDirector.open('http://www.imvu.com/catalog/
    web_manage_badges.php?action=grant-revoke&creator_badge_index=1',
    params)
    data = form.read()
    form.close()
    print(data)

    Error Message:
    Traceback (most recent call last):
    File "C:\Python31\htmlparser.py", line 34, in <module>
    form = urllib.request.OpenerDirector.open('http://www.imvu.com/
    catalog/web_manage_badges.php?action=grant-
    revoke&creator_badge_index=1', params)
    File "C:\Python31\lib\urllib\request.py", line 332, in open
    req = Request(fullurl, data)
    File "C:\Python31\lib\urllib\request.py", line 174, in __init__
    self._parse()
    File "C:\Python31\lib\urllib\request.py", line 179, in _parse
    raise ValueError("unknown url type: %s" % self.full_url)
    ValueError: unknown url type: grant-userid=Guest_xLolKittyx
     
    SuperMetroid, Oct 12, 2009
    #1
    1. Advertising

  2. >>>>> SuperMetroid <> (S) wrote:

    >S> The html code of the form, and my code are below. I can't get the
    >S> value to post/submit.. instead I get an error. Can anyone help?


    >S> HTML Code of Form:
    >S> <form method='post' autocomplete='off'>
    >S> <input type='hidden' name='action' value='grant-revoke' />
    >S> <input type='hidden' name='creator_badge_index' value='1' />


    >S> <input type='hidden' name='token'
    >S> value='92dcd92a8bc16f73f330d118ae1ed891' />
    >S> <input type='hidden' name='do-grant' value='1' />
    >S> <div id='grant-div'><span class='label'>Grant badge: </span><input
    >S> type='text' id='grant-userid' name='grant-userid' value='userid /
    >S> avatar name' /><input type='submit' value='Grant!' /></div>
    >S> </form>


    >S> My Code:
    >S> opener = urllib.request.build_opener()
    >S> cj = http.cookiejar.MozillaCookieJar()
    >S> cj.load('C:/Users/Alison/Documents/moz_cookies.txt')
    >S> opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor
    >S> (cj))


    >S> params = urllib.parse.urlencode({'grant-userid' : 'Guest_xLolKittyx'})
    >S> form = urllib.request.OpenerDirector.open('http://www.imvu.com/catalog/
    >S> web_manage_badges.php?action=grant-revoke&creator_badge_index=1',
    >S> params)


    You are mixing GET-type (indicated by ? in the URL) and POST-type
    parameters. Put the action and creator_badge_index parameters also in
    the dictionary. And probably you need to provide the other hidden fields
    from the form also.

    Something like (untested):

    paramdict = {
    'action': 'grant-revoke',
    'creator_badge_index': '1',
    'token': '92dcd92a8bc16f73f330d118ae1ed891',
    'do-grant': '1',
    'grant-userid' : 'Guest_xLolKittyx',
    }
    params = urllib.parse.urlencode(paramdict)
    url = 'http://www.imvu.com/catalog/web_manage_badges.php'
    form = urllib.request.OpenerDirector.open(url, params)
    --
    Piet van Oostrum <>
    WWW: http://pietvanoostrum.com/
    PGP key: [8DAE142BE17999C4]
     
    Piet van Oostrum, Oct 13, 2009
    #2
    1. Advertising

  3. SuperMetroid

    SuperMetroid Guest

    Thank you so much for the quick response. I tried exactly what you
    said but it still yields an error.. :/

    Here is the Error Message:
    Traceback (most recent call last):
    File "C:\Python31\htmlparser.py", line 40, in <module>
    form = urllib.request.OpenerDirector.open('http://www.imvu.com/
    catalog/web_manage_badges.php?action=grant-
    revoke&creator_badge_index=1', params)
    File "C:\Python31\lib\urllib\request.py", line 332, in open
    req = Request(fullurl, data)
    File "C:\Python31\lib\urllib\request.py", line 174, in __init__
    self._parse()
    File "C:\Python31\lib\urllib\request.py", line 179, in _parse
    raise ValueError("unknown url type: %s" % self.full_url)
    ValueError: unknown url type: action=grant-
    revoke&creator_badge_index=1&token=92dcd92a8bc16f73f330d118ae1ed891&do-
    grant=1&grant-userid=Guest_xLolKittyx
     
    SuperMetroid, Oct 13, 2009
    #3
  4. SuperMetroid

    SuperMetroid Guest

    Oops. Now I changed the URL, as you suggested, and I get the same
    error.
     
    SuperMetroid, Oct 13, 2009
    #4
  5. SuperMetroid

    SuperMetroid Guest

    Anyway.. I'll close this thread, since Piet is helping me somewhere
    else.

    No more responses here are needed, thanks.
     
    SuperMetroid, Oct 13, 2009
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    1
    Views:
    1,794
  2. Ghafran Abbas
    Replies:
    0
    Views:
    4,304
    Ghafran Abbas
    Oct 12, 2004
  3. Andy Fish

    how to make a form that won't submit

    Andy Fish, Aug 28, 2003, in forum: Javascript
    Replies:
    2
    Views:
    137
  4. Joop
    Replies:
    5
    Views:
    631
  5. Replies:
    3
    Views:
    784
Loading...

Share This Page