473,666 Members | 2,368 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form Value Won't Post/Submit

SuperMetroid
5 New Member
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 3803
pietvo
2 New Member
You are mixing GET-type (indicated by ? in the URL) and POST-type
parameters. Put the action and creator_badge_i ndex 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
SuperMetroid
5 New Member
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 New Member
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
SuperMetroid
5 New Member
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
3806
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 it's 22. ?!? I have iterated through the form collection and printed out every key on both machines and compared them carefully. They are identical. WTF is going on here? I even went so far as to reset IIS on both machines, and the counts are...
4
7787
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: The form won't submit if the link is clicked, but will submit if the SUBMIT button is clicked. I need to call a function to change the form's action according to user's input before it is submitted.
12
2463
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" HTML----------- Form is ----> <form action="thanks.php" method="post" name="contact_form" id="contact_form"> Name -------> <input type="text" name="name" id="name" size="25"> Button sends code -----> <input type="button" value="Submit Form"
3
5383
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 there is a sample file called Ixtrasp.asp, but I could not find it in my system although I installed indexing service. I followed the steps in MSDN site to create a basic .asp query form (too long to post it here), but it always displays: No...
6
4037
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 on it... (Kinda like a menu, you make your choice from) But since this table can get very long, I've put something of a 'search-form' on top, which enables the user to make a
2
2295
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 can use that will work for both browsers, or is there something wrong with my code? I seem to think that the problem lies with the "onclick" area of the form. This is my code, such as it is... <SCRIPT LANGUAGE="JavaScript">
5
17696
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 type=password maxlength="8" name="password" value="`pss`"> where usr and pss are sent from the previous form.
16
2860
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 ass and the app will be used internally so I'm not too worried about users who aren't using javascript. I'm using the following javascript to detect whether or not they've hit enter: if(document.layers) {
10
6843
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 validate some inputs of this form, so I submit it to a PHP page in my own server first.
10
2187
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
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6191
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.