due to a faulty server design, I'm having to stream down JSON and correct a null byte if I find one. I'm using python requests
to do this. Each JSON event is delimited by a \n
. What I am trying to do here is pull down a chunk (which will always be less than one log line). Search through that chunk for the end of event signifier ("\"status\":\d+\d+\d+}}\n"
).
If that signifier is there I will do something with the full JSON event, if not, I add that chunk to a buffer, b
, then grab the next chunk and look for the identifier. As soon as I get this down, I'll start searching for the null byte.
b = ""
for d in r.iter_content(chunk_size=25):
s = re.search("\"status\":\d+\d+\d+}}\n", d)
if s:
d = d.split("\n", 1)
fullLogLine = b + d[0]
b = d[1]
else:
b = b + d
I'm completely losing the value of b in this case. It doesn't seem to carry over through the iter_content
. Whenever I try to print the value of just b
it's empty. I feel I'm missing something obvious here. Anything helps. Thanks.