Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Form Value Won't Post/Submit

Reply
Thread Tools

Form Value Won't Post/Submit

 
 
SuperMetroid
Guest
Posts: n/a
 
      10-12-2009
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.HTTPCoo kieProcessor
(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
 
Reply With Quote
 
 
 
 
Piet van Oostrum
Guest
Posts: n/a
 
      10-13-2009
>>>>> SuperMetroid <(E-Mail Removed)> (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.HTTPCoo kieProcessor
>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 <(E-Mail Removed)>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
 
Reply With Quote
 
 
 
 
SuperMetroid
Guest
Posts: n/a
 
      10-13-2009
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=92dcd92a8bc16f7 3f330d118ae1ed891&do-
grant=1&grant-userid=Guest_xLolKittyx
 
Reply With Quote
 
SuperMetroid
Guest
Posts: n/a
 
      10-13-2009
Oops. Now I changed the URL, as you suggested, and I get the same
error.
 
Reply With Quote
 
SuperMetroid
Guest
Posts: n/a
 
      10-13-2009
Anyway.. I'll close this thread, since Piet is helping me somewhere
else.

No more responses here are needed, thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to retrieve form field value if form is EncType=multipart/form-dataForm? Li Zhang ASP .Net 4 02-27-2009 01:23 AM
Loop Form - extract display 'value' as well as form value? ASP General 2 02-20-2006 09:36 PM
Form Input Value to change a later value Christa Lee Javascript 2 10-01-2005 07:56 PM
Pass a form value that is different from selected value Iceman HTML 1 01-07-2004 03:29 PM
how to change the value of a hidden form value on submit Matt Herson Javascript 8 09-30-2003 05:18 AM



Advertisments