Form Value Won't Post/Submit
Piet van Oostrum
piet at cs.uu.nl
Tue Oct 13 05:02:08 EDT 2009
>>>>> SuperMetroid <xsupermetroidx at gmail.com> (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 <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
More information about the Python-list
mailing list