{"action":"opened","issue":{"url":"https://api.github.com/repos/kevin1024/vcrpy/issues/163","labels_url":"https://api.github.com/repos/kevin1024/vcrpy/issues/163/labels{/name}","comments_url":"https://api.github.com/repos/kevin1024/vcrpy/issues/163/comments","events_url":"https://api.github.com/repos/kevin1024/vcrpy/issues/163/events","html_url":"https://github.com/kevin1024/vcrpy/issues/163","id":92477107,"number":163,"title":"Sharing cassettes between Python 2 and 3 is tricky (when matching on body)","user":{"login":"gward","id":51437,"avatar_url":"https://avatars.githubusercontent.com/u/51437?v=3","gravatar_id":"","url":"https://api.github.com/users/gward","html_url":"https://github.com/gward","followers_url":"https://api.github.com/users/gward/followers","following_url":"https://api.github.com/users/gward/following{/other_user}","gists_url":"https://api.github.com/users/gward/gists{/gist_id}","starred_url":"https://api.github.com/users/gward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gward/subscriptions","organizations_url":"https://api.github.com/users/gward/orgs","repos_url":"https://api.github.com/users/gward/repos","events_url":"https://api.github.com/users/gward/events{/privacy}","received_events_url":"https://api.github.com/users/gward/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-01T20:21:23Z","updated_at":"2015-07-01T20:21:23Z","closed_at":null,"body":"I have a test that needs to match on the request body, because it sends a POST. This works fine in a pure Python 2 world, and it works fine in a pure Python 3 world. Things get tricky when you need the same code to work under both Python 2 and 3.\r\n\r\nSpecifically, if I first run my tests under Python 2, then my cassette files store bodies like this:\r\n```\r\ninteractions:\r\n- request:\r\n    body: 'hello world\r\n\r\n      how are you today?'\r\n[...]\r\n```\r\n\r\nIf I then run my test under Python 3, it fails because the bodies don't match:\r\n```\r\nE\r\n======================================================================\r\nERROR: test_echo_with_body (tests.test_echo.TestEchoClient)\r\n----------------------------------------------------------------------\r\nTraceback (most recent call last):\r\n  File \"/home/gward/src/python-renesys-apis/tests/test_echo.py\", line 24, in test_echo_with_body\r\n    response = call_echo(body)\r\n  File \"/home/gward/src/python-renesys-apis/tests/test_echo.py\", line 10, in call_echo\r\n    return urllib.request.urlopen(req)\r\n  File \"/usr/lib/python3.4/urllib/request.py\", line 161, in urlopen\r\n    return opener.open(url, data, timeout)\r\n  File \"/usr/lib/python3.4/urllib/request.py\", line 463, in open\r\n    response = self._open(req, data)\r\n  File \"/usr/lib/python3.4/urllib/request.py\", line 481, in _open\r\n    '_open', req)\r\n  File \"/usr/lib/python3.4/urllib/request.py\", line 441, in _call_chain\r\n    result = func(*args)\r\n  File \"/usr/lib/python3.4/urllib/request.py\", line 1210, in http_open\r\n    return self.do_open(http.client.HTTPConnection, req)\r\n  File \"/usr/lib/python3.4/urllib/request.py\", line 1185, in do_open\r\n    r = h.getresponse()\r\n  File \"/var/lib/venv/ren3/lib/python3.4/site-packages/vcr/stubs/__init__.py\", line 236, in getresponse\r\n    self.cassette.record_mode)\r\nnose.proxy.CannotOverwriteExistingCassetteException: No match for the request (<Request (POST) http://gerg.ca/echo.cgi>) was found. Can't overwrite existing cassette ('echo_with_body.yaml') in your current record mode ('once').\r\n-------------------- >> begin captured logging << --------------------\r\nvcr.cassette: DEBUG: Entered context for cassette at echo_with_body.yaml.\r\nvcr.stubs: DEBUG: Got <Request (POST) http://gerg.ca/echo.cgi>\r\nvcr.matchers: DEBUG: Requests <Request (POST) http://gerg.ca/echo.cgi> and <Request (POST) http://gerg.ca/echo.cgi> differ according to the following matchers: [(False, <function body at 0x7fb22cb21e18>)]\r\nvcr.cassette: DEBUG: Exiting context for cassette at echo_with_body.yaml.\r\n--------------------- >> end captured logging << ---------------------\r\n```\r\n\r\nThe workaround appears to be to regenerate my cassettes under Python 3. Then they look like this:\r\n```\r\ninteractions:\r\n- request:\r\n    body: !!binary |\r\n      aGVsbG8gd29ybGQKaG93IGFyZSB5b3UgdG9kYXk/\r\n[...]\r\n```\r\nand the tests pass under Python 2 and 3.\r\n\r\nTwo problems:\r\n* regenerating all my cassettes is a pain the neck; I'd rather not if I can avoid it\r\n* if that is the best we can do, it really should be documented!\r\n"}}