Python Forum
Problem: Retrieving Form data - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problem: Retrieving Form data (/thread-30115.html)



Problem: Retrieving Form data - PythonDev - Oct-05-2020

Hi,
I'm using CGI to interact with form fields as shown in the example below:

# Function -> Main method that receives parameters that handles request and response
def application(environ, v_response):
    # Function -> Retrieves inputs from input forms
    a_inp = cgi.FieldStorage(environ["wsgi.input"], environ=environ)
When testing if I can get the value entered from the fields using getvalue() I can get it without problems, as in the example below:

v_inp = a_inp.getlist("v_name")
Having as answer the value entered in the form field:

return v_inp
>> joao
In the application I develop I need to check the variable (v_inp) to be able to go through a threat detection process of xss and sql injection (based on regular expressions, for this I use the (re) python module) to remove the characters (parentheses) of the string to avoid problems in passing threat detection, below I demonstrate the original and disassembled string:

v_inp (original)

v_inp = FieldStorage(None, None, [MiniFieldStorage('v_name', 'João')])
v_inp (disassembled)
v_inp = FieldStorage None, None, [MiniFieldStorage 'v_name', 'João' ]
Being disassembled according to the example above I can check if there is any threat from xss or sqlinjection to the passage through the threat detection process.
After checking I do the assembly assigning the start and original value of the string:

v_inp = FieldStorage(None, None, [MiniFieldStorage('v_name', 'João')])
But I run into this error (AttributeError: 'str' object has no attribute 'getvalue') when trying to get the value of the field using the syntax below:

v_out = v_inp.getvalue("v_name")
return v_out
How can I solve this problem?


RE: Problem: Retrieving Form data - PythonDev - Oct-06-2020

(Oct-05-2020, 10:52 PM)PythonDev Wrote: Hi,
I'm using CGI to interact with form fields as shown in the example below:

# Function -> Main method that receives parameters that handles request and response
def application(environ, v_response):
    # Function -> Retrieves inputs from input forms
    a_inp = cgi.FieldStorage(environ["wsgi.input"], environ=environ)
When testing if I can get the value entered from the fields using getvalue() I can get it without problems, as in the example below:

v_inp = a_inp.getlist("v_name")
Having as answer the value entered in the form field:

return v_inp
>> joao
In the application I develop I need to check the variable (v_inp) to be able to go through a threat detection process of xss and sql injection (based on regular expressions, for this I use the (re) python module) to remove the characters (parentheses) of the string to avoid problems in passing threat detection, below I demonstrate the original and disassembled string:

v_inp (original)

v_inp = FieldStorage(None, None, [MiniFieldStorage('v_name', 'João')])
v_inp (disassembled)
v_inp = FieldStorage None, None, [MiniFieldStorage 'v_name', 'João' ]
Being disassembled according to the example above I can check if there is any threat from xss or sqlinjection to the passage through the threat detection process.
After checking I do the assembly assigning the start and original value of the string:

v_inp = FieldStorage(None, None, [MiniFieldStorage('v_name', 'João')])
But I run into this error (AttributeError: 'str' object has no attribute 'getvalue') when trying to get the value of the field using the syntax below:

v_out = v_inp.getvalue("v_name")
return v_out
How can I solve this problem?

I was able to verify that the data typ (v_inp), before going through the threat detection process is like :

(<class 'cgi.FieldStorage'>)
after the process even being reassembled it is like:
(<class 'str'>)
How can I convert the data type from (<class 'str'>) to (<class 'cgi.FieldStorage'>)


Convert data type - PythonDev - Oct-06-2020

Hi,

I have two exits that present two types of data. In the first variable, I return the data type below:

return (type(v_inp_one))
>> <class 'cgi.FieldStorage'>
In the second variable, I return the data type below:

return (type(v_inp_two))
>> <class 'str'>
Now I need to convert the variable to type ( <class 'str'> ) for type ( <class 'cgi.FieldStorage'> ), how do I do this?


RE: Convert data type - PythonDev - Oct-16-2020

(Oct-06-2020, 06:06 PM)PythonDev Wrote: Hi,

I have two exits that present two types of data. In the first variable, I return the data type below:

return (type(v_inp_one))
>> <class 'cgi.FieldStorage'>
In the second variable, I return the data type below:

return (type(v_inp_two))
>> <class 'str'>
Now I need to convert the variable to type ( <class 'str'> ) for type ( <class 'cgi.FieldStorage'> ), how do I do this?
v_inp_two = "MiniFieldStorage('v_name', 'João'), MiniFieldStorage('v_sname', 'Aguiar')"
I was able to make the change as follows:
v_inp_one = cgi.FieldStorage(v_inp_two)
return (type(v_inp_one)
>> <class 'cgi.FieldStorage')
Now the problem is that it does not load the list of fields and values inside the quilt when checking out:
FieldStorage(None, None, [])
how do I insert the variable list inside the bracket v_inp_two ? Remembering that the data type must be <class 'cgi.FieldStorage'>.