What I wanted to do -Open a specific http.conf and get the port number with a regular expression -Store the acquired number in a variable and spit it out with yaml
But the following error occurred
vh_https_port = self.func_extract_port("^<VirtualHost \*:", ">", vh_port_line_https)
*vh_port_line_https=A string containing the port number
def func_extract_port(self, pattern_s, pattern_e, string):
try:
#Exclude commented out lines
regex = r'(\d{1,5})'
r = re.compile(pattern_s+regex+pattern_e)
result_word = r.search(string)
except:
print(string+"Against"+pattern_s+"When"+ pattern_e +"I searched for but not found")
result_word = ""
return result_word
yaml.representer.RepresenterError: cannot represent an object: <_sre.SRE_Match object; span=(0, 21), match='<VirtualHost *:1111>'>
The result obtained by search is not a string that is a match object, so even if it can be stored in a variable, I was angry that it could not be represented.
result_word = r.search(string).group(1) And made the return value of the function a string
Recommended Posts