django - HTTP request with Python : TypeError: an integer is required (got type socket) -
django - HTTP request with Python : TypeError: an integer is required (got type socket) -
i'm facing unusual bug while trying retrieve resource via http. seems happen http client (tried requests , urllib same results).
my project uses django, , run tests using tox , standard django command python manage.py test
. when run test suite , unit test makes http request (e.g via requests.get('http://example.com')
), tests fails error, test suite go on until end, , hangs. have manually kill process via command line.
after investigations, set try / except
block arount http request, , got next stacktrace:
file "/mycomputer/python3.4/site-packages/requests/api.py", line 68, in homecoming request('get', url, **kwargs) file "/mycomputer/python3.4/site-packages/requests/api.py", line 50, in request response = session.request(method=method, url=url, **kwargs) file "/mycomputer/python3.4/site-packages/requests/sessions.py", line 464, in request resp = self.send(prep, **send_kwargs) file "/mycomputer/python3.4/site-packages/requests/sessions.py", line 576, in send r = adapter.send(request, **kwargs) file "/mycomputer/python3.4/site-packages/requests/adapters.py", line 370, in send timeout=timeout file "/mycomputer/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 544, in urlopen body=body, headers=headers) file "/mycomputer/python3.4/site-packages/requests/packages/urllib3/connectionpool.py", line 349, in _make_request conn.request(method, url, **httplib_request_kw) file "/usr/lib/python3.4/http/client.py", line 1065, in request self._send_request(method, url, body, headers) file "/usr/lib/python3.4/http/client.py", line 1103, in _send_request self.endheaders(body) file "/usr/lib/python3.4/http/client.py", line 1061, in endheaders self._send_output(message_body) file "/usr/lib/python3.4/http/client.py", line 906, in _send_output self.send(msg) file "/usr/lib/python3.4/http/client.py", line 841, in send self.connect() file "/mycomputer/python3.4/site-packages/requests/packages/urllib3/connection.py", line 155, in connect conn = self._new_conn() file "/mycomputer/python3.4/site-packages/requests/packages/urllib3/connection.py", line 134, in _new_conn (self.host, self.port), self.timeout, **extra_kw) file "/mycomputer/python3.4/site-packages/requests/packages/urllib3/util/connection.py", line 68, in create_connection sock = socket.socket(af, socktype, proto) file "/usr/lib/python3.4/socket.py", line 123, in __init__ _socket.socket.__init__(self, family, type, proto, fileno) typeerror: integer required (got type socket)
i don't understand problem here. running same thing command line works perfectly, it's related project architecture. also, running test suite on computer fails same way.
have meet similar issue ? can do track downwards problem ?
okay, problem caused httpretty, third-party bundle utilize mocking.
python django unit-testing http request
Comments
Post a Comment