Thor77 / TeamspeakStats

A simple Teamspeak stats-generator - based on server-logs
MIT License
19 stars 2 forks source link

Encoding issues with python2 #3

Closed UnR34L closed 7 years ago

UnR34L commented 7 years ago

tsstats -l /var/log/teamspeak/ts3server*.log -o /root/stats.html

Getting this error: "tsstats: error: unrecognized arguments:"

FreeBSD Server.

Thor77 commented 7 years ago

That doesn't look like an error from tsstats. Or was there more output than that (if so, please post the complete traceback)? Try quoting the globbing path (tsstats -l "/var/log/teamspeak/ts3server*.log" [...]), maybe your shell tries to expand it itself.

UnR34L commented 7 years ago
root@teamspeak_10:/ # tsstats -l "/var/log/teamspeak/ts3server*.log" -o /root/stats.html
Traceback (most recent call last):
  File "/usr/local/bin/tsstats", line 9, in <module>
    load_entry_point('tsstats==0.12.0', 'console_scripts', 'tsstats')()
  File "/usr/local/lib/python2.7/site-packages/tsstats/__main__.py", line 60, in cli
    main(configuration)
  File "/usr/local/lib/python2.7/site-packages/tsstats/__main__.py", line 94, in main
    datetime_fmt=configuration.get('General', 'datetimeformat')
  File "/usr/local/lib/python2.7/site-packages/tsstats/template.py", line 69, in render_template
    creation_time=datetime.now()))
  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/tsstats/template.html", line 27, in top-level template code
    {% set id = headline_id + "." + client.nick %}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 8: ordinal not in range(128)

Right so, adding the quotes gave a different output ^

Thor77 commented 7 years ago

Which python-version are you running? Please try running python -c "import sys;print(sys.getdefaultencoding()) to see your encoding. It seems like your current encoding can't decode a byte in a clients nickname. Setting a locale with UTF-8 support should fix that (not sure how to do that on FreeBSD, though).

UnR34L commented 7 years ago

My locale appears to be setup correctly now (it wasn't before):

root@teamspeak_10:/ # locale
LANG=en_GB.UTF-8
LC_CTYPE="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_ALL=

This is the output from python.

root@teamspeak_10:/ # python2.7 -c 'import sys; print(sys.getdefaultencoding())'
ascii
Thor77 commented 7 years ago

Did you try to run tsstats after your locale-change? It should work fine with these.

UnR34L commented 7 years ago

Yes, I ran it after every change I made, logged out a few times and even restarted the jail.

your current encoding can't decode a byte in a Clients nickname

This feels like the problem, I randomly selected a few log files, one of them worked, it had four clients.

http://image.prntscr.com/image/bdceb3f3dd0d494bbe1239b16f92dd06.png

UnR34L commented 7 years ago

Having no locale set may have borked the ts3 logs.

Thanks for your time, cool project.

Thor77 commented 7 years ago

Hm, I don't really think that's the (only) problem.

This feels like the problem, I randomly selected a few log files, one of them worked, it had four clients. screenshot

These numbers don't look correct oO This issue could be debugged by using the debug-mode (passing -d), though.

Can you post the affected nicks (from the log-files that didn't parse correctly) for further debugging? To make sure the problem is really with your old locale, you could restart your teamspeak3-server, join with a nick with chars not supported by ansii in it and try to parse the new-logfile with tsstats.

Thanks for your help :)

UnR34L commented 7 years ago

Unrelated but interesting, I used three months of logs, I had a connection time of over 1000 days.. in three months.

It's working with one months worth of logs, but to be safe I've used todays logs and it's looking accurate.

Redacted

Would it be helpful to give you a log I know is not working ?

Redacted

Thor77 commented 7 years ago

Yeah, that's very helpful, thanks 👍 screenshot Hm, these numbers don't look too wrong to me (not >1000d of onlinetime at least). Can't really reproduce your issue. It's working fine on my machine. Are you still referring to your encoding-issue or to insane onlinetimes?

UnR34L commented 7 years ago

Encoding issues, since using that log file gives errors.

As for the >1000 days, finding that file would take some effort (137 log files in total)

Using that same log file I showed you, this is the output with '-d' but seems to be the same output as before.

root@teamspeak_10:/ # /usr/local/bin/tsstats -d -l "/var/log/teamspeak/ts3server_2016-07-08__08_30_40.259891_1.log" -o /media/index.html
Traceback (most recent call last):
  File "/usr/local/bin/tsstats", line 9, in <module>
    load_entry_point('tsstats==0.12.0', 'console_scripts', 'tsstats')()
  File "/usr/local/lib/python2.7/site-packages/tsstats/__main__.py", line 60, in cli
    main(configuration)
  File "/usr/local/lib/python2.7/site-packages/tsstats/__main__.py", line 94, in main
    datetime_fmt=configuration.get('General', 'datetimeformat')
  File "/usr/local/lib/python2.7/site-packages/tsstats/template.py", line 69, in render_template
    creation_time=datetime.now()))
  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 989, in render
    return self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/tsstats/template.html", line 27, in top-level template code
    {% set id = headline_id + "." + client.nick %}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 8: ordinal not in range(128)

Right now, I just started fresh only using recent log files and there's no issues with weird online times or errors.

Thor77 commented 7 years ago

Ah, I can reproduce your error in Python 2.7 (couldn't in Python 3.5), will hunt that down and comment here as soon as I find a solution. Thanks again for providing the logfile.

Thor77 commented 7 years ago

Fixed in 0.12.5, you can upgrade with pip install --upgrade tsstats. Please close this issue, if you can confirm the fix.

UnR34L commented 7 years ago

Fixed =)