From 06fdd78f91cbfa2160b37038cf93ff303e05da9d Mon Sep 17 00:00:00 2001 From: Chris Mayo Date: Sun, 15 Sep 2019 19:42:29 +0100 Subject: [PATCH] Python3: fix TypeError in HttpUrl.read_content() From test_http_redirect: File "linkchecker/linkcheck/checker/httpurl.py", line 323, in read_content line: buf.write(data) locals: buf = <_io.StringIO object at 0x7f8fe2f45e10> buf.write = data = b'Recursive Redirect\n' TypeError: string argument expected, got 'bytes' --- linkcheck/checker/httpurl.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/linkcheck/checker/httpurl.py b/linkcheck/checker/httpurl.py index b29b8d75..809a6d0e 100644 --- a/linkcheck/checker/httpurl.py +++ b/linkcheck/checker/httpurl.py @@ -26,11 +26,7 @@ import requests import warnings warnings.simplefilter('ignore', requests.packages.urllib3.exceptions.InsecureRequestWarning) -try: - from cStringIO import StringIO -except ImportError: - # Python 3 - from io import StringIO +from io import BytesIO from .. import (log, LOG_CHECK, strformat, mimeutil, url as urlutil, LinkCheckerError, httputil) @@ -316,7 +312,7 @@ class HttpUrl (internpaturl.InternPatternUrl, proxysupport.ProxySupport): """Return data and data size for this URL. Can be overridden in subclasses.""" maxbytes = self.aggregate.config["maxfilesizedownload"] - buf = StringIO() + buf = BytesIO() for data in self.url_connection.iter_content(chunk_size=self.ReadChunkBytes): if buf.tell() + len(data) > maxbytes: raise LinkCheckerError(_("File size too large"))