Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error: Nested method ?
#1
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)
Reply
#2
Please add in the full text of the error.
Reply
#3
(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
Reply
#4
Use proper error code tag while posting
pyzyx3qwerty
"The greatest glory in living lies not in never falling, but in rising every time we fall." - Nelson Mandela
Need help on the forum? Visit help @ python forum
For learning more and more about python, visit Python docs
Reply
#5
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.
Reply
#6
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Read nested data from JSON - Getting an error marlonbown 5 1,309 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Error on nested loop : Invalid syntax dvazquezgu 3 3,178 Nov-25-2020, 10:04 AM
Last Post: palladium
  Type error when reading in different data types on an __init__ method Dylanmull 3 2,748 May-09-2019, 02:05 PM
Last Post: buran
  Index error using pop in nested loop PerksPlus 3 3,345 Mar-28-2019, 03:11 PM
Last Post: ichabod801
  Getting error when called through instance method aankrose 2 2,537 Mar-02-2019, 07:19 PM
Last Post: aankrose

Forum Jump:

User Panel Messages

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