From 22555df56a90615d64c886d4655ed1be95e04408 Mon Sep 17 00:00:00 2001 From: Pablo Hoffman Date: Sun, 27 Jun 2010 19:32:26 -0300 Subject: [PATCH] response_httprepr: fixed error with unknown response codes (closes #169) --- scrapy/tests/test_utils_response.py | 3 +++ scrapy/utils/response.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scrapy/tests/test_utils_response.py b/scrapy/tests/test_utils_response.py index 3b2b2226f..231969f0a 100644 --- a/scrapy/tests/test_utils_response.py +++ b/scrapy/tests/test_utils_response.py @@ -129,6 +129,9 @@ class ResponseUtilsTest(unittest.TestCase): r1 = Response("http://www.example.com", status=404, headers={"Content-type": "text/html"}, body="Some body") self.assertEqual(response_httprepr(r1), 'HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\n\r\nSome body') + r1 = Response("http://www.example.com", status=6666, headers={"Content-type": "text/html"}, body="Some body") + self.assertEqual(response_httprepr(r1), 'HTTP/1.1 6666 \r\nContent-Type: text/html\r\n\r\nSome body') + def test_get_cached_beautifulsoup(self): r1 = Response('http://www.example.com', body='') diff --git a/scrapy/utils/response.py b/scrapy/utils/response.py index 95ae3df32..a691d8875 100644 --- a/scrapy/utils/response.py +++ b/scrapy/utils/response.py @@ -85,7 +85,7 @@ def response_httprepr(response): that was received (that's not exposed by Twisted). """ - s = "HTTP/1.1 %d %s\r\n" % (response.status, RESPONSES[response.status]) + s = "HTTP/1.1 %d %s\r\n" % (response.status, RESPONSES.get(response.status, '')) if response.headers: s += response.headers.to_string() + "\r\n" s += "\r\n"