Skip to content

Commit

Permalink
do not fail with 500 error with ANSI encoding; fixes #54
Browse files Browse the repository at this point in the history
  • Loading branch information
bast committed Jun 4, 2018
1 parent 43f23f5 commit 837305f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cicero/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
import json

# FIXME: rather use requests.get
if sys.version_info[0] > 2:
from urllib import request
_urlopen = request.urlopen
Expand Down Expand Up @@ -73,9 +74,9 @@ def render_github_markdown(path, engine, engine_version):
try:
url = prefix + '/' + last_file

response = _urlopen(url)
response = requests.get(url)
markdown = response.text

markdown = response.read().decode("utf-8")
if markdown == 'Not Found':
return flask.render_template('404.html')

Expand Down
8 changes: 6 additions & 2 deletions cicero/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ def home():

config = current_app.config

with io.open(config['filename'], 'r', encoding='utf-8') as mkdfile:
markdown = mkdfile.read()
try:
with io.open(config['filename'], 'r', encoding='utf-8') as mkdfile:
markdown = mkdfile.read()
except UnicodeDecodeError:
with io.open(config['filename'], 'r', encoding='cp1252') as mkdfile:
markdown = mkdfile.read()

title = extract_title(markdown)
markdown = fix_images(markdown, 'images/')
Expand Down

0 comments on commit 837305f

Please sign in to comment.