]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
fix proxy for Python 2
authorSamuel Fekete <samuel.fekete@hogarthww.com>
Fri, 3 Nov 2017 11:39:13 +0000 (11:39 +0000)
committerSamuel Fekete <samuel.fekete@gmail.com>
Fri, 13 Jul 2018 15:44:19 +0000 (16:44 +0100)
tests/integration/test_proxy.py

index a1fc003890241909790761221e536a2e47846ad6..5dfd285e906867e0a0a1ae8f99c04da693c9ee5b 100644 (file)
@@ -23,8 +23,15 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
     '''
     def do_GET(self):
         upstream_response = urlopen(self.path)
-        self.send_response(upstream_response.status, upstream_response.msg)
-        for header in upstream_response.headers.items():
+        try:
+            status = upstream_response.status
+            headers = upstream_response.headers.items()
+        except AttributeError:
+            # In Python 2 the response is an addinfourl instance.
+            status = upstream_response.code
+            headers = upstream_response.info().items()
+        self.send_response(status, upstream_response.msg)
+        for header in headers:
             self.send_header(*header)
         self.end_headers()
         self.copyfile(upstream_response, self.wfile)