View Single Post
Old Jan 2nd, 2006, 2:18 PM   #2
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
For a self-proclaimed newbie to Python, you've gone about trying to solve the problem in a very intelligent and sensible way. For the most part, you appear to do everything perfectly correct.

The only thing I can spot that might be wrong with it is the URL you send the POST data to. I took a look at the source for the Sandbox edit page, and noticed this line:
<form id="editform" name="editform" method="post" action="/w/index.php?title=
Wikipedia:Sandbox&amp;action=submit" enctype="multipart/form-data">
The edit form appears to submit with "action=submit", whilst the URL you pass to urllib has "action=edit". At a guess, I'd say that the 'edit' action displays the edit page, whilst the 'submit' action is designed to handle data submitted from forms.

Try changing your urllib call to:
f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Wikipedia:Sand
box&action=submit", params)
And see if that makes any difference. Also, the default edit page for the sandbox contains the line:
{{Please leave this line alone (sandbox heading)}}
So it might be an idea to prepend this line to your wpTextbox1 value:
urllib.urlencode({
    'wpTextbox1': "{{Please leave this line alone (sandbox heading)}}\ntest1", 
    'wpCommment': 'This is the first test', 'wpSave':1})
Just so that you don't mess anything up for Wikipedia
Arevos is offline   Reply With Quote