{"action":"created","issue":{"url":"https://api.github.com/repos/gabrielfalcao/HTTPretty/issues/311","repository_url":"https://api.github.com/repos/gabrielfalcao/HTTPretty","labels_url":"https://api.github.com/repos/gabrielfalcao/HTTPretty/issues/311/labels{/name}","comments_url":"https://api.github.com/repos/gabrielfalcao/HTTPretty/issues/311/comments","events_url":"https://api.github.com/repos/gabrielfalcao/HTTPretty/issues/311/events","html_url":"https://github.com/gabrielfalcao/HTTPretty/issues/311","id":186595291,"number":311,"title":"incompatibility with docker-py - _socketobject' object has no attribute '_host'","user":{"login":"dtenenba","id":2286826,"avatar_url":"https://avatars.githubusercontent.com/u/2286826?v=3","gravatar_id":"","url":"https://api.github.com/users/dtenenba","html_url":"https://github.com/dtenenba","followers_url":"https://api.github.com/users/dtenenba/followers","following_url":"https://api.github.com/users/dtenenba/following{/other_user}","gists_url":"https://api.github.com/users/dtenenba/gists{/gist_id}","starred_url":"https://api.github.com/users/dtenenba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtenenba/subscriptions","organizations_url":"https://api.github.com/users/dtenenba/orgs","repos_url":"https://api.github.com/users/dtenenba/repos","events_url":"https://api.github.com/users/dtenenba/events{/privacy}","received_events_url":"https://api.github.com/users/dtenenba/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-01T17:31:08Z","updated_at":"2016-11-01T18:58:03Z","closed_at":null,"body":"If I call the [docker-py API](https://github.com/docker/docker-py) while inside a function decorated with `@httpretty.activate`, I get an error. To reproduce you will need to install docker and then `pip install docker-py`. \r\n\r\nCode:\r\n\r\n```python\r\nimport httpretty\r\nimport docker\r\n\r\n@httpretty.activate\r\ndef test_example():\r\n    client = docker.Client()\r\n    images = client.images()\r\n\r\ntest_example()\r\n```\r\n\r\nProduces the stack trace below. Without the decorator it works fine.\r\nThis is with \r\n\r\n```\r\n$ pip freeze |grep pretty\r\nhttpretty==0.8.14\r\n```\r\n\r\nI originally posted this as an [issue](https://github.com/spulec/moto/issues/749) against `moto` because I hadn't tried to reproduce it with httpretty alone. \r\n\r\nCan this be fixed? I am dead in the water until it is. \r\nUnfortunately the function I want to test uses both docker and AWS (endpoints that I want to mock) so short of a major refactor of my code, I can't work around this.\r\n\r\nHere is the stack trace:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"t.py\", line 9, in <module>\r\n    test_example()\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/httpretty-0.8.14-py2.7.egg/httpretty/core.py\", line 1240, in wrapper\r\n    return test(*args, **kw)\r\n  File \"t.py\", line 7, in test_example\r\n    images = client.images()\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/docker/api/image.py\", line 40, in images\r\n    res = self._result(self._get(self._url(\"/images/json\"), params=params),\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/docker/utils/decorators.py\", line 47, in inner\r\n    return f(self, *args, **kwargs)\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/docker/client.py\", line 132, in _get\r\n    return self.get(url, **self._set_request_timeout(kwargs))\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/requests/sessions.py\", line 488, in get\r\n    return self.request('GET', url, **kwargs)\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/requests/sessions.py\", line 475, in request\r\n    resp = self.send(prep, **send_kwargs)\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/requests/sessions.py\", line 596, in send\r\n    r = adapter.send(request, **kwargs)\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/requests/adapters.py\", line 423, in send\r\n    timeout=timeout\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py\", line 595, in urlopen\r\n    chunked=chunked)\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py\", line 363, in _make_request\r\n    conn.request(method, url, **httplib_request_kw)\r\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py\", line 1053, in request\r\n    self._send_request(method, url, body, headers)\r\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py\", line 1093, in _send_request\r\n    self.endheaders(body)\r\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py\", line 1049, in endheaders\r\n    self._send_output(message_body)\r\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py\", line 893, in _send_output\r\n    self.send(msg)\r\n  File \"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py\", line 869, in send\r\n    self.sock.sendall(data)\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/httpretty-0.8.14-py2.7.egg/httpretty/core.py\", line 487, in sendall\r\n    hostname=self._host,\r\n  File \"/Users/dtenenba/envs/gemstrigger/lib/python2.7/site-packages/httpretty-0.8.14-py2.7.egg/httpretty/core.py\", line 544, in __getattr__\r\n    return getattr(self.truesock, name)\r\nAttributeError: '_socketobject' object has no attribute '_host'\r\n```"},"comment":{"url":"https://api.github.com/repos/gabrielfalcao/HTTPretty/issues/comments/257660604","html_url":"https://github.com/gabrielfalcao/HTTPretty/issues/311#issuecomment-257660604","issue_url":"https://api.github.com/repos/gabrielfalcao/HTTPretty/issues/311","id":257660604,"user":{"login":"dtenenba","id":2286826,"avatar_url":"https://avatars.githubusercontent.com/u/2286826?v=3","gravatar_id":"","url":"https://api.github.com/users/dtenenba","html_url":"https://github.com/dtenenba","followers_url":"https://api.github.com/users/dtenenba/followers","following_url":"https://api.github.com/users/dtenenba/following{/other_user}","gists_url":"https://api.github.com/users/dtenenba/gists{/gist_id}","starred_url":"https://api.github.com/users/dtenenba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dtenenba/subscriptions","organizations_url":"https://api.github.com/users/dtenenba/orgs","repos_url":"https://api.github.com/users/dtenenba/repos","events_url":"https://api.github.com/users/dtenenba/events{/privacy}","received_events_url":"https://api.github.com/users/dtenenba/received_events","type":"User","site_admin":false},"created_at":"2016-11-01T18:58:03Z","updated_at":"2016-11-01T18:58:03Z","body":"If anyone else runs into this, I came up with a hacky workaround. It's not ideal because it means I have to change the code under test because of this issue.\r\n\r\nI do this:\r\n\r\n```python\r\nimport docker\r\nimport httpretty\r\n\r\n\r\n@contextmanager\r\ndef turn_httpretty_off():\r\n    if httpretty.is_enabled():\r\n        httpretty.disable()\r\n    yield\r\n    if not httpretty.is_enabled():\r\n        httpretty.enable()\r\n\r\n```\r\n\r\nThen later in the function I want to test:\r\n\r\n```python\r\ndef some_function_that_calls_web_services_and_uses_docker():\r\n    # call web services here (tests will mock the endpoints)\r\n    with turn_httpretty_off():\r\n        # do stuff with docker here\r\n    # call more web services\r\n```\r\n\r\n"}}
{"actor":{"display_login":"dtenenba"}}