Python Forum

Full Version: Error: Nested method ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi people.

In the method of a class I receive parameters for data processing. As a solution I had to nest methods to be able to sequence the code, but I encounter the following error (TypeError: expected string or bytes-like object), the error presented when I nested the method, below follows the detailed code:

# Native Module, Import : re, regex
import re, json

# Name Class: CrositeScript
class CrositeScript:

    def m_purl (o_output, v_url, v_inp):

        # Regex Condition - exist if check
        if re.search (
           r "my-regex",
           v_url, re.IGNORECASE
        ):
            # Variable: get response status for client browser:
            status = "200 OK"
            # Variable: obtain http header for client browser
            headers = [("Content-type", "application/json; charset=utf-8")]
            # Function: Sending variable to the client browser:
            o_output (status, headers)
            # Output:
            return "msg ..."

        else:
            # ...
            def m_pinp (o_output, v_url, v_inp):
            
               # Regex Condition - exist if check
               if re.search (
                  r "my-regex",
                  v_inp, re.IGNORECASE
               ):
                  # Variable: get response status for client browser:
                  status = "200 OK"
                  # Variable: obtain http header for client browser
                  headers = [("Content-type", "application/json; charset=utf-8")]
                  # Function: Sending variable to the client browser:
                  o_output (status, headers)
                  # Output:
                  return "msg ..."
               
               else:
                  v_keo = v_inp.getvalue("v_query")
                  # Convert to dictionary
                  o_data = dict()
                  # Pre-structure for the json format
                  o_data ["term"] = "The search term -" + v_keo
                  # Output in json format
                  v_json = json.dumps(o_data)

                  # Variable: get response status for client browser:
                  status = "200 OK"
                  # Variable: obtain http header for client browser
                  headers = [("Content-type", "application/json; charset = utf-8")]
                  # Function: Sending variable to the client browser:
                  o_output (status, headers)
                  # Method Return Instruction:
                  return v_json

        return m_pinp (o_output, v_url, v_inp)
Please add in the full text of the error.
(May-03-2020, 02:34 AM)bowlofred Wrote: [ -> ]Please add in the full text of the error.


Error:
Traceback (most recent call last): File "/usr/local/lib/python3.7/wsgiref/handlers.py", line 137, in run self.result = application(self.environ, self.start_response) File "runwsgi.py", line 29, in apps return [str(GetEntry.m_parser(o_output, v_url)).encode("utf-8")] File "/home/assistant/PycharmProjects/kosmos/corework/request/getentry.py", line 38, in m_parser return ThreatDetect.m_get(o_output, v_url) File "/home/assistant/PycharmProjects/kosmos/corework/security/threatdetect.py", line 33, in m_get return CrositeScript.m_get(o_output, v_url) File "/home/assistant/PycharmProjects/kosmos/corework/security/crositescript.py", line 50, in m_get return SqlInjection.m_get(o_output, v_url) File "/home/assistant/PycharmProjects/kosmos/corework/security/sqlinjection.py", line 40, in m_get return GetExit.m_parser(o_output, v_url) File "/home/assistant/PycharmProjects/kosmos/corework/request/getexit.py", line 36, in m_parser return StaticsFiles.m_parser(o_output, v_url) File "/home/assistant/PycharmProjects/kosmos/corework/flows/staticsfiles.py", line 350, in m_parser o_file = open(v_filedir + "fgs/" + o_fame, "r") FileNotFoundError: [Errno 2] No such file or directory: 'apps/favicon.ico/assets/fgs/favicon.ico' 127.0.0.1 - - [03/May/2020 06:50:45] "GET /favicon.ico HTTP/1.1" 500 59 Traceback (most recent call last): File "/usr/local/lib/python3.7/wsgiref/handlers.py", line 137, in run self.result = application(self.environ, self.start_response) File "runwsgi.py", line 35, in apps return [str(PostEntry.m_parser(o_output, v_url, v_inp)).encode("utf-8")] File "/home/assistant/PycharmProjects/kosmos/corework/response/postentry.py", line 11, in m_parser return ThreatDetect.m_post(o_output, v_url, v_inp) File "/home/assistant/PycharmProjects/kosmos/corework/security/threatdetect.py", line 41, in m_post return CrositeScript.m_post(o_output, v_url, v_inp) File "/home/assistant/PycharmProjects/kosmos/corework/security/crositescript.py", line 102, in m_post v_inp, re.IGNORECASE File "/home/assistant/.virtualenvs/wse/lib/python3.7/re.py", line 183, in search return _compile(pattern, flags).search(string) TypeError: expected string or bytes-like object 127.0.0.1 - - [03/May/2020 06:50:49] "POST /release/runcode/query HTTP/1.1" 500 59
Use proper error code tag while posting
I don't know why you aren't getting flagged for a syntax error for r "my-regex", but when I change that to r"my-regex" things run until I get to v_keo = v_inp.getvalue("v_query") which makes sense since I'm definitely not passing the right thing in a v_inp.
(May-03-2020, 01:55 PM)deanhystad Wrote: [ -> ]I don't know why you aren't getting flagged for a syntax error for r "my-regex", but when I change that to r"my-regex" things run until I get to v_keo = v_inp.getvalue("v_query") which makes sense since I'm definitely not passing the right thing in a v_inp.

my-regex was just to exemplify probably generate an error, it should not be considered and if testing it is enough to insert a valid expression.