@mock_s3 permanently breaks requests library
See original GitHub issueAt first look, I thought this was a duplicate of https://github.com/spulec/moto/issues/303.
However, on further inspection, the problem is only present with the mock_s3
decorator, not with the mock_s3_deprecated
decorator. Therefore, if my inspection of the code base is right, this looks like a problem related to the responses
library or the use of it in moto
, whereas https://github.com/spulec/moto/issues/303 concerned the HTTPretty library.
Anyway, the meat of the issue:
After using @mock_s3
in django tests, other test classes that use LiveserverTestCase
and the requests
library stop working, and fail with the error: ConnectionError: Connection refused
.
This is not an inherent problem with responses
itself, as the following test demonstrates:
python -c "from moto.packages.responses.responses import mock; import requests; mock.start(); mock.stop(); print requests.get('http://google.com')"
<Response [200]>
However, if mock.stop()
is omitted, you see the same error as in the django test:
python -c "from moto.packages.responses.responses import mock; import requests; mock.start(); print requests.get('http://google.com')"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/REDACTED/env/local/lib/python2.7/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/home/REDACTED/env/local/lib/python2.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/home/REDACTED/env/local/lib/python2.7/site-packages/requests/sessions.py", line 502, in request
resp = self.send(prep, **send_kwargs)
File "/home/REDACTED/env/local/lib/python2.7/site-packages/requests/sessions.py", line 612, in send
r = adapter.send(request, **kwargs)
File "/home/REDACTED/env/local/lib/python2.7/site-packages/moto/packages/responses/responses.py", line 302, in unbound_on_send
return self._on_request(adapter, request, *a, **kwargs)
File "/home/REDACTED/env/local/lib/python2.7/site-packages/moto/packages/responses/responses.py", line 244, in _on_request
raise response
requests.exceptions.ConnectionError: Connection refused: GET http://google.com/
This suggests to me that, one way or another, moto is failing to call mock.stop()
.
moto version 1.0.1 Django version 1.11.3
Issue Analytics
- State:
- Created 6 years ago
- Reactions:18
- Comments:31 (9 by maintainers)
Top GitHub Comments
@yhvh A workaround for this for now is:
As of moto 1.3.5 this works: