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
4 3803
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): - 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)
Thanks for the response! I changed the code, but I still get an error when it is run.. :/
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', 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
-
Oh, and I tried it without the hidden fields as well, but I still get an error.
OK, there is another problem that I overlooked. - 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: - opener = urllib.request.build_opener(....)
-
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: - form = urllib.request.urlopen(url, params)
(this one tested)
I'll close this thread, since Piet is helping me elsewhere. Thanks for everything Piet!
No more responses needed here.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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.
|
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"
|
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...
|
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
| |
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">
|
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.
|
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)
{
|
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.
|
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>
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |