KC7-Foundation / kc7

A cybersecurity game in Azure Data Explorer
https://kc7cyber.com
Apache License 2.0
162 stars 14 forks source link

UnicodeDecodeError: #57

Closed phoenixindicus closed 1 year ago

phoenixindicus commented 2 years ago

Traceback (most recent call last): File "C:\cyber-challenger\app.py", line 1, in from app import application File "C:\cyber-challenger\app__init.py", line 37, in from app.server.views import main File "C:\cyber-challenger\app\server\views.py", line 18, in from app.server.modules.logging.uploadLogs import LogUploader File "C:\cyber-challenger\app\server\modules\logging\uploadLogs.py", line 18, in from app.server.modules.email.email import Email File "C:\cyber-challenger\app\server\modules\email\email.py", line 13, in from app.server.modules.actors.Actor import Actor File "C:\cyber-challenger\app\server\modules\actors\Actor.py", line 19, in sentenceGenerator = SentenceGenerator() File "C:\cyber-challenger\app\server\modules\helpers\markov_sentence_generator.py", line 14, in init__ self.load_words() File "C:\cyber-challenger\app\server\modules\helpers\markov_sentence_generator.py", line 42, in load_words response = f.read() File "C:\Users\xxxx\AppData\Local\Programs\Python\Python310\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 8315: character maps to

This isssue is fixed when you use encoding='utf8' in open function - def load_words(self): """ Load a list of words from a given text url """ if "http" in self.word_source: response = requests.get(self.word_source).text else: with open(self.word_source , encoding='utf8') as f: response = f.read()

    # remove unwanted characters
    table = str.maketrans(dict.fromkeys('#<>-'))
    response = response.translate(table)
gregs1998 commented 1 year ago

This is resolved in latest refactor of SentenceGenerator

83