473,394 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Form Value Won't Post/Submit

SuperMetroid
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:
Expand|Select|Wrap|Line Numbers
  1. <form method='post' autocomplete='off'>
  2.     <input type='hidden' name='action' value='grant-revoke' />
  3.     <input type='hidden' name='creator_badge_index' value='1' />
  4.  
  5.     <input type='hidden' name='token' value='92dcd92a8bc16f73f330d118ae1ed891' />
  6.     <input type='hidden' name='do-grant' value='1' />
  7.     <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>
  8. </form>
My Code:
Expand|Select|Wrap|Line Numbers
  1. opener = urllib.request.build_opener()
  2. cj = http.cookiejar.MozillaCookieJar()
  3. cj.load('C:/Users/Alison/Documents/moz_cookies.txt')
  4. opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
  5.  
  6. params = urllib.parse.urlencode({'grant-userid' : 'Guest_xLolKittyx'})
  7. form = urllib.request.OpenerDirector.open('http://www.imvu.com/catalog/web_manage_badges.php?action=grant-revoke&creator_badge_index=1', params)
  8. data = form.read()
  9. form.close()
  10. print(data)
Error Message:
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Python31\htmlparser.py", line 34, in <module>
  3.     form = urllib.request.OpenerDirector.open('http://www.imvu.com/catalog/web_manage_badges.php?action=grant-revoke&creator_badge_index=1', params)
  4.   File "C:\Python31\lib\urllib\request.py", line 332, in open
  5.     req = Request(fullurl, data)
  6.   File "C:\Python31\lib\urllib\request.py", line 174, in __init__
  7.     self._parse()
  8.   File "C:\Python31\lib\urllib\request.py", line 179, in _parse
  9.     raise ValueError("unknown url type: %s" % self.full_url)
  10. ValueError: unknown url type: grant-userid=Guest_xLolKittyx
Oct 12 '09 #1
4 3795
pietvo
2
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):

Expand|Select|Wrap|Line Numbers
  1. paramdict = {
  2.           'action': 'grant-revoke',
  3.           'creator_badge_index': '1',
  4.           'token': '92dcd92a8bc16f73f330d118ae1ed891',
  5.           'do-grant': '1',
  6.           'grant-userid' : 'Guest_xLolKittyx',
  7.           }
  8. params = urllib.parse.urlencode(paramdict)
  9. url = 'http://www.imvu.com/catalog/web_manage_badges.php'
  10. form = urllib.request.OpenerDirector.open(url, params)
Oct 13 '09 #2
Thanks for the response! I changed the code, but I still get an error when it is run.. :/

Error Message:
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:\Python31\htmlparser.py", line 40, in <module>
  3.     form = urllib.request.OpenerDirector.open('http://www.imvu.com/catalog/web_manage_badges.php', params)
  4.   File "C:\Python31\lib\urllib\request.py", line 332, in open
  5.     req = Request(fullurl, data)
  6.   File "C:\Python31\lib\urllib\request.py", line 174, in __init__
  7.     self._parse()
  8.   File "C:\Python31\lib\urllib\request.py", line 179, in _parse
  9.     raise ValueError("unknown url type: %s" % self.full_url)
  10. ValueError: unknown url type: action=grant-revoke&creator_badge_index=1&token=92dcd92a8bc16f73f330d118ae1ed891&do-grant=1&grant-userid=Guest_xLolKittyx
  11.  
Oh, and I tried it without the hidden fields as well, but I still get an error.
Oct 13 '09 #3
pietvo
2
OK, there is another problem that I overlooked.
Expand|Select|Wrap|Line Numbers
  1. form = urllib.request.OpenerDirector.open(url, params)
is the wrong way to send the request. OpenerDirector.open is an instance method of the class OpenerDirector, not a class method. So that only works if you make an instance and then call the method on that. Like:
Expand|Select|Wrap|Line Numbers
  1. opener = urllib.request.build_opener(....)
  2. form = opener.open(url, params)
That is only useful if you want a special opener, for example with authentication. In the simple cases you can get away with the standard opener by using urlopen:
Expand|Select|Wrap|Line Numbers
  1. form = urllib.request.urlopen(url, params)
(this one tested)
Oct 13 '09 #4
I'll close this thread, since Piet is helping me elsewhere. Thanks for everything Piet!

No more responses needed here.
Oct 13 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chris Nelder | last post by:
I think I must be losing my mind here. I've got the same page running on two different machines. I do the same form post on both, and on one machine I get Request.Form.Count=21 and on the other...
4
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM:...
12
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" ...
3
by: Harvey | last post by:
Hi, I try to write an asp query form that lets client search any text-string and display all pages in my web server that contain the text. I have IIS 6.0 on a server 2003. The MSDN site says...
6
by: Joop | last post by:
Hi all, I'm kinda new to JavaScript, but hey... I'm trying anyway! ;-) So, here's my problem : I've created a table in my document, presenting a list of items, one can 'select' by clicking...
2
by: webbedfeet | last post by:
Hi I hope someone can help me. I have a client side form validation script which works perfectly in IE but clicking "Submit" in Mozilla does nothing - the form won't submit. Is there something I...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
16
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the...
10
by: kelvin | last post by:
Hi, A difficult question. I have a form that I used to submit to https://www. paypal.com/cgi-bin/ webscr <form action="https://www. paypal.com/cgi-bin/webscr" method="post"> Now I need to...
10
by: Kelly | last post by:
Can anyone tell me what I'm doing wrong here? ================================== <html> <head> <title>Test Form</title> <script language="JavaScript" type="text/javascript"> </head>
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.