I am parsing information using the GET request with a web client. I have a concatenated string based on that data where I'd like to split the string based on this pattern: "\r\n". I basically want each bit of header info on its own line. Also I'd like to exclude the body information.
Here is a portion of a sample string I'd like to split:
'HTTP/1.1 400 Bad Request\\r\\nDate: Tue, 26 Oct 2021 11:26:46 GMT\\r\\nServer:
I have a function where I parse the information and I've tried using regex and split but I keep getting errors (I am new to python and networking). Here are some examples of what I've tried (webinformation is the string to split):
header = webinformation.splitlines()
for x in range(len(header)):
print(header[x])
Here is one example of the regular expressions I've tried
print(re.split('\\r\\n', webinformation))
How could I print each bit of information on its own line? I'm not sure if this is an issue with escape characters maybe?
re.split(r'\\r\\n', webinformation)
to avoid the double escaping.