{"action":"created","issue":{"url":"https://api.github.com/repos/sigmavirus24/betamax/issues/96","repository_url":"https://api.github.com/repos/sigmavirus24/betamax","labels_url":"https://api.github.com/repos/sigmavirus24/betamax/issues/96/labels{/name}","comments_url":"https://api.github.com/repos/sigmavirus24/betamax/issues/96/comments","events_url":"https://api.github.com/repos/sigmavirus24/betamax/issues/96/events","html_url":"https://github.com/sigmavirus24/betamax/issues/96","id":141175851,"number":96,"title":"gethostbyname slowing things down on OS X","user":{"login":"bboe","id":48100,"avatar_url":"https://avatars.githubusercontent.com/u/48100?v=3","gravatar_id":"","url":"https://api.github.com/users/bboe","html_url":"https://github.com/bboe","followers_url":"https://api.github.com/users/bboe/followers","following_url":"https://api.github.com/users/bboe/following{/other_user}","gists_url":"https://api.github.com/users/bboe/gists{/gist_id}","starred_url":"https://api.github.com/users/bboe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bboe/subscriptions","organizations_url":"https://api.github.com/users/bboe/orgs","repos_url":"https://api.github.com/users/bboe/repos","events_url":"https://api.github.com/users/bboe/events{/privacy}","received_events_url":"https://api.github.com/users/bboe/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-03-16T05:20:10Z","updated_at":"2016-03-16T16:54:00Z","closed_at":null,"body":"I finally got annoyed that my integration tests would periodically slow down. After running a profiler I saw that `socket.gethostbyname` was the bottleneck. I adapted the betamax example to show the stacktrace that shows that `socket.gethostbyname` is indeed being called. I'm guessing that it probably shouldn't be.\r\n\r\n```\r\n../.venv/pc/lib/python2.7/site-packages/requests-2.9.1-py2.7.egg/requests/sessions.py:480: in get\r\n    return self.request('GET', url, **kwargs)\r\n../.venv/pc/lib/python2.7/site-packages/requests-2.9.1-py2.7.egg/requests/sessions.py:459: in request\r\n    prep.url, proxies, stream, verify, cert\r\n../.venv/pc/lib/python2.7/site-packages/requests-2.9.1-py2.7.egg/requests/sessions.py:617: in merge_environment_settings\r\n    env_proxies = get_environ_proxies(url) or {}\r\n../.venv/pc/lib/python2.7/site-packages/requests-2.9.1-py2.7.egg/requests/utils.py:562: in get_environ_proxies\r\n    if should_bypass_proxies(url):\r\n../.venv/pc/lib/python2.7/site-packages/requests-2.9.1-py2.7.egg/requests/utils.py:551: in should_bypass_proxies\r\n    bypass = proxy_bypass(netloc)\r\n/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py:1487: in proxy_bypass\r\n    return proxy_bypass_macosx_sysconf(host)\r\n/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py:1454: in proxy_bypass_macosx_sysconf\r\n    hostIP = ip2num(hostIP)\r\n```\r\n\r\nHere's the example\r\n\r\n```python\r\nfrom betamax import Betamax\r\nfrom requests import Session\r\nfrom unittest import TestCase\r\n\r\nwith Betamax.configure() as config:\r\n    config.cassette_library_dir = '.'\r\n\r\nimport socket\r\n# comment the next line out when creating the cassette\r\nsocket.gethostbyname = lambda x: None\r\n\r\n\r\nclass TestGitHubAPI(TestCase):\r\n    def setUp(self):\r\n        self.session = Session()\r\n\r\n    # Set the cassette in line with the context declaration\r\n    def test_repo(self):\r\n        with Betamax(self.session).use_cassette('repo'):\r\n            resp = self.session.get(\r\n                'https://api.github.com/repos/sigmavirus24/github3.py'\r\n                )\r\n            assert resp.json()['owner'] != {}\r\n```\r\n\r\n`socket.gethostbyname` does not get called when I tested from a linux machine."},"comment":{"url":"https://api.github.com/repos/sigmavirus24/betamax/issues/comments/197421312","html_url":"https://github.com/sigmavirus24/betamax/issues/96#issuecomment-197421312","issue_url":"https://api.github.com/repos/sigmavirus24/betamax/issues/96","id":197421312,"user":{"login":"sigmavirus24","id":240830,"avatar_url":"https://avatars.githubusercontent.com/u/240830?v=3","gravatar_id":"","url":"https://api.github.com/users/sigmavirus24","html_url":"https://github.com/sigmavirus24","followers_url":"https://api.github.com/users/sigmavirus24/followers","following_url":"https://api.github.com/users/sigmavirus24/following{/other_user}","gists_url":"https://api.github.com/users/sigmavirus24/gists{/gist_id}","starred_url":"https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sigmavirus24/subscriptions","organizations_url":"https://api.github.com/users/sigmavirus24/orgs","repos_url":"https://api.github.com/users/sigmavirus24/repos","events_url":"https://api.github.com/users/sigmavirus24/events{/privacy}","received_events_url":"https://api.github.com/users/sigmavirus24/received_events","type":"User","site_admin":false},"created_at":"2016-03-16T16:54:00Z","updated_at":"2016-03-16T16:54:00Z","body":"> Rather than monkey patching the standard library, perhaps betamax could augment requests to bypass the check for proxies when a cassette is present.\r\n\r\nSo the point of Betamax working the way it does is to avoid monkey-patching anything. That said, if we want to prevent requests from using this, we need to monkey-patch requests (but, again, only when the cassette is already recorded).\r\n\r\nI understand the frustration with this.\r\n\r\n> Maybe there's a separate issue here which is preventing those DNS responses from being cached; they're all for the same host.\r\n\r\nThat would be a requests specific question IMO. I can look into it tonight maybe."}}