Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Can only POST to CGI Scripts" 501 error
    primarykey
    data
    text
    <p>I'm running a local CGIHttpServer in Python, and am using this python program to run something in that server:</p> <pre><code>''' submit data to form using robots ''' import urllib import pprint # hacking gullible app url = "http://localhost:8000/cgi-bin/w5/captcha.example/vote_app/gullible_app.py" def vote(lecturer): params = urllib.urlencode({'lecturer': lecturer,'submit':'submit'}) f = urllib.urlopen(url, params) pprint.pprint(f.fp.readlines()) vote("Ivo") </code></pre> <p>This tells me it can only POST to CGI scripts, which I find really strange because the python script opens in my web browser at that address just fine. So... it's running in my browser fine, but not when the python program attempts to POST to that URL. What is going on here? (There is VERY little out there on the internet about this - I've tried researching this problem to solve it myself but there's only 3-4 people mentioning this issue)</p> <p>EDIT: Sorry guys! I did not understand GET and POST. I should have included this in the question - it is the python program "gullible_app.py". As you can see, the form does the "POST" operation</p> <pre><code>import cgi import cgitb; cgitb.enable() # form generation # ------------------------------------------------------- def print_form(): print "Content-Type: text/html\n" print ''' &lt;html&gt; &lt;body&gt; &lt;form method="post" action="gullible_app.py"&gt; &lt;p&gt;Select your favorite lecturer:&lt;/p&gt; &lt;input type="radio" name="lecturer" value="harald" /&gt; Harald &lt;input type="radio" name="lecturer" value="ivo" /&gt; Ivo &lt;input type="submit" name="submit" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; ''' # response generation # ------------------------------------------------------- def print_response(): print 'Content-Type: text/html\n' print '&lt;html&gt;&lt;body&gt;Thank you for your vote!&lt;/body&gt;&lt;/html&gt;' def main(): user_data = cgi.FieldStorage() if "submit" in user_data: # user press "submit" lecturer = user_data.getfirst("lecturer") f = open( "cgi-bin\\w5\\captcha.example\\vote_app\\votes.txt", "a" ) f.write( lecturer+'\n' ) f.close() print_response() else: # display the form print_form() main() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload