Skip to content

fix UnicodeDecodeError - #5

Open
mdcramer wants to merge 1 commit into
danwiesenthal:masterfrom
mdcramer:fix-UnicodeDecodeError
Open

fix UnicodeDecodeError#5
mdcramer wants to merge 1 commit into
danwiesenthal:masterfrom
mdcramer:fix-UnicodeDecodeError

Conversation

@mdcramer

Copy link
Copy Markdown

Hello Dan - I greatly enjoyed your presentation on Nov 14th (Introduction to Python for Data Science: Coding the Naive Bayes Algorithm). The combination of theory and code was excellent, especially given the format with all of the people.

When I ran your code on my Windows machine, however, I got this:

runfile('C:/Users/mcram/Documents/Github/Naive-Bayes-Evening-Workshop/run.py', wdir='C:/Users/mcram/Documents/Github/Naive-Bayes-Evening-Workshop')
Ok let's go!
Traceback (most recent call last):
File "", line 1, in
runfile('C:/Users/mcram/Documents/Github/Naive-Bayes-Evening-Workshop/run.py', wdir='C:/Users/mcram/Documents/Github/Naive-Bayes-Evening-Workshop')
File "C:\Users\mcram\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 710, in runfile
execfile(filename, namespace)
File "C:\Users\mcram\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 101, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Users/mcram/Documents/Github/Naive-Bayes-Evening-Workshop/run.py", line 16, in
json_text = load_json_files(datasource_info, verbose=True)
File "C:\Users\mcram\Documents\Github\Naive-Bayes-Evening-Workshop\datasource.py", line 12, in load_json_files
scraped_pages[name] = json.load(json_data, encoding="utf8")
File "C:\Users\mcram\Anaconda3\lib\json_init_.py", line 296, in load
return loads(fp.read(),
File "C:\Users\mcram\Anaconda3\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 0x8d in position 4562891: character maps to

I just now reproduced the error. In my pull request I added encoding="utf8" to open(filepath, encoding="utf8") in datasource.py in order to avoid the error above. Please let me know if you have any questions.

added encoding="utf8" to open(filepath, encoding="utf8") in datasource.py in order to avoid "UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 4562891: character maps to <undefined>"
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

Successfully merging this pull request may close these issues.

1 participant