May-03-2020, 12:23 AM
(This post was last modified: May-03-2020, 12:26 AM by JohnnyCoffee.)
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:
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)
