Skip to content

Commit

Permalink
Fixed the default_url_fetcher for Python 2, which returns a message…
Browse files Browse the repository at this point in the history
… type with no `get_filename` method
  • Loading branch information
cleitner committed Apr 22, 2014
1 parent a084a5b commit a8a951b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion weasyprint/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ def default_url_fetcher(url):
url = iri_to_uri(url)
result, mime_type, charset = urlopen_contenttype(Request(
url, headers={'User-Agent': VERSION_STRING}))
filename = result.info().get_filename()
filename = None
try:
filename = result.info().get_filename()
except AttributeError:
# Python 2 doesn't return a message with the get_filename method
pass
return dict(file_obj=result, redirected_url=result.geturl(),
mime_type=mime_type, encoding=charset, filename=filename)
else:
Expand Down

0 comments on commit a8a951b

Please sign in to comment.