Skip to content

Error processing log with special character #125

Open
@pditmar

Description

@pditmar

During the processing of logs by the Azure Log Forwarder we are experiencing the following error :

2025-06-11T12:22:01Z   [Error]   [release-0.2.4] Failed to process logs
Traceback (most recent call last):
  File "/home/site/wwwroot/logs_ingest/main.py", line 195, in parse_to_json
    event_json = json.loads(text)
  File "/usr/local/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 11303 (char 11302)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/site/wwwroot/logs_ingest/main.py", line 198, in parse_to_json
    event_json = json.loads(text.replace("\n", ""), strict=False)
  File "/usr/local/lib/python3.9/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
  File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 11303 (char 11302)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/site/wwwroot/logs_ingest/main.py", line 201, in parse_to_json
    event_json = json.loads(text.replace("\'", "\""))
  File "/usr/local/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 681 (char 680)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/site/wwwroot/logs_ingest/main.py", line 204, in parse_to_json
    event_json = json.loads(text.replace('\\\'', '').replace("\'", "\""), strict=False)
  File "/usr/local/lib/python3.9/json/__init__.py", line 359, in loads
    return cls(**kw).decode(s)
  File "/usr/local/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.9/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 681 (char 680)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/site/wwwroot/logs_ingest/main.py", line 62, in process_logs
    logs_to_be_sent_to_dt = extract_logs(events, self_monitoring)
  File "/home/site/wwwroot/logs_ingest/main.py", line 92, in extract_logs
    event_json = parse_to_json(event_body)
  File "/home/site/wwwroot/logs_ingest/main.py", line 207, in parse_to_json
    f"Failed to decode JSON for the event (base64 applied for safety!): {util_misc.to_base64_text(str(text))}.",
  File "/home/site/wwwroot/logs_ingest/util/util_misc.py", line 6, in to_base64_text
    encoded_bytes = base64.b64encode(text.encode('ascii'))
UnicodeEncodeError: 'ascii' codec can't encode character '\xf6' in position 12788: ordinal not in range(128)

Part of the log we are ingesting contains "ProductName":"CLIENT XXöXXXXX"

xf6 is the umlaut character.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions