Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeDecodeError raised by log view #15

Open
kmierzeje opened this issue Aug 24, 2020 · 2 comments
Open

UnicodeDecodeError raised by log view #15

kmierzeje opened this issue Aug 24, 2020 · 2 comments
Milestone

Comments

@kmierzeje
Copy link

kmierzeje commented Aug 24, 2020

UnicodeDecodeError at /admin/logs/get-log-line/1/ 'ascii' codec can't decode byte

Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/logtailer/views.py", line 56, in get_log_lines
content = get_history(file, history)
File "/usr/local/lib/python3.8/site-packages/logtailer/views.py", line 31, in get_history
data.append(f.read(buffer_size))
File "/usr/lib64/python3.8/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]

The error makes it impossible to view log.
Please make the encoding configurable is settings or in LogFile model or most preferably in both places.

Even if correct encoding is configured, the error might still appear if log contains invalid codepoints. logtailer should be resilient to such characters - replace them with '?' or something...

Django Version: 3.0.8
Python Version: 3.8.3

@fireantology
Copy link
Owner

Can you upload a log file that reproduces the error ?

Thanks
Regards

@kmierzeje
Copy link
Author

test.log

I reproduced it on Windows, so default codec is cp1250 not ascii, but effect is the same. I got a different call stack:

UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 5: character maps to

Traceback (most recent call last):
File "C:\apps\Python37\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\apps\Python37\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\apps\Python37\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "C:\apps\Python37\lib\site-packages\logtailer\views.py", line 64, in get_log_lines
for line in file:
File "C:\apps\Python37\lib\encodings\cp1250.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]

@fireantology fireantology added this to the Django 4.0 milestone Dec 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants