Python Forum
Problem: Retrieving Form data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem: Retrieving Form data
#1
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?
Reply
#2
(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'>)
Reply
#3
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?
Reply
#4
(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'>.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  KeyError while retrieving ESPN data john317ab 2 807 Nov-29-2023, 09:07 PM
Last Post: john317ab
  Sending data from the form to DB quisatz 6 1,308 Nov-13-2023, 09:23 AM
Last Post: Annaat20
  .get() not retrieving value? Sedos101 2 560 Aug-25-2023, 11:48 AM
Last Post: deanhystad
  Unable to request image from FORM Data usman 0 990 Aug-18-2022, 06:23 PM
Last Post: usman
  [Solved] Retrieving a pdf from sqlite3 BigMan 4 2,313 Mar-12-2022, 01:56 PM
Last Post: deanhystad
  Retrieving a column from a data set using a function Bayle 6 2,329 Oct-06-2021, 08:52 PM
Last Post: Bayle
  Looking for data/info on a perticular data-proccesing problem. MvGulik 9 3,850 May-01-2021, 07:43 AM
Last Post: MvGulik
  Retrieving Cookies whois1230 2 2,172 Nov-21-2020, 12:01 PM
Last Post: snippsat
  Retrieving dictionary keys within with another dictionay bazcurtis 8 2,817 Oct-29-2019, 10:06 PM
Last Post: bazcurtis
  Retrieving items from JSON bazcurtis 12 5,047 Oct-27-2019, 05:18 PM
Last Post: bazcurtis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020