2

I would like to call my Python script from different location ( FIY: I will call it later from my paypal registration process).

My configuration: I am running my website on AmazonWebServices. IIS8. Python3

I am calling to my python with this simple HTML file:

<form role="form" action="http://www.mywebsite.nz/cgi-bin/mypythonfile.py" method="post">

    <label for="person_name">Person name</label>                    
    <input id="person_name" type="text" name="person_name">

    <label for="email_address">Email address</label>                    
    <input id="email_address" type="text" name="email_address">

    <button id="submit_button" type="submit" >submit</button>

</form>

Here is what I have in my mypythonfile.py:

import cgi, cgitb


#Create instance of FieldStorage
form = cgi.FieldStorage() 
cgitb.enable()


#Here I will collect all parameters
variable = ""
value = ""
allFields = ""
for key in form.keys():
    variable = str(key)
    value = str(form.getvalue(variable))
    allFields += variable + ":" + value + "   "

print(allFields)

But the result I get is with empty values:

<email_address>:<None>  <person_name>:<None>

p.s. When calling the .py from the same place where the HTML file is - everything works perfectly. The problem happens when I call the .py file from an external HTML.

How can I fix it? (maybe it is some sort of configuration I have to add e.g. to IIS?)

1 Answer 1

3

You are sending it as POST. To obtain POST variables, try replacing:

form = cgi.FieldStorage()

with this:

form = cgi.FieldStorage(environ="post")

Or you can try this:

import sys, urllib
query_string = sys.stdin.read()
multiform = urllib.parse.parse_qs(query_string)

And now you can use this:

multiform["email_address"]
Sign up to request clarification or add additional context in comments.

14 Comments

The cgitb is good for debugging, but you have not started it, you need to do: cgitb.enable()
Try using a library for this. Follow this answer: stackoverflow.com/a/464977/4898487
Check if you are submitting right fields and retrieving right fields.
Sorry. But maybe you are right, I have once read that some servers have it blocked.
I am using apache but I have found this: stackoverflow.com/questions/3472429/…. But it's for iis6 and iis7, I hope this will work for iis8 too.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.