Skip to content

Commit

Permalink
Force utf-8 encoding on reading files
Browse files Browse the repository at this point in the history
This avoid errors like UnicodeDecodeError: 'ascii' codec can't decode ...
  • Loading branch information
viniciuschiele committed Jul 20, 2017
1 parent 2bf53db commit fa1a5e3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions flask_apidoc/apidoc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import codecs
import json
import mimetypes

Expand Down Expand Up @@ -91,7 +92,7 @@ def __send_api_file(self, file_name):

file_name = join(self.app.static_folder, file_name)

with open(file_name, 'rt') as file:
with codecs.open(file_name, 'r', 'utf-8') as file:
data = file.read()

# replaces the hard coded url by the
Expand Down Expand Up @@ -128,7 +129,7 @@ def __send_main_file(self, file_name):

file_name = join(self.app.static_folder, file_name)

with open(file_name, 'rt') as file:
with codecs.open(file_name, 'r', 'utf-8') as file:
data = file.read()

data = data.replace(
Expand Down

0 comments on commit fa1a5e3

Please sign in to comment.