Skip to content
Myr

Merge pull request #767 from stefanp/develop

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Wrap socket.error in ConnectionError (+ unit tests)

authored by Kenneth Reitz · committed by Kenneth Reitz · parents d4f7d67, 875c9e1 · Browse files · 2 files+18 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+18 added−0 removed

  • tests:+14 added−0 removed
  • other:+4 added−0 removed

2 files+18 added−0 removed

modified:requests/models.py+4 added
6 unmodified lines
7This module contains the primary objects that power Requests.8"""910import os11import socket12from datetime import datetime1314from .hooks import dispatch_hook, HOOKS15from .structures import CaseInsensitiveDict
599 unmodified lines
615 timeout=self.timeout,616 )617 self.sent = True618619 except socket.error as sockerr:620 raise ConnectionError(sockerr)621622 except MaxRetryError as e:623 raise ConnectionError(e)624625 except (_SSLError, _HTTPError) as e:
237 unmodified lines
modified:tests/test_requests.py+14 added
809 unmodified lines
810 ds2 = pickle.loads(pickle.dumps(requests.session(prefetch=False)))811 assert ds1.prefetch812 assert not ds2.prefetch813814 def test_connection_error(self):815 try:816 get('http://localhost:1/nope')817 except requests.ConnectionError:818 pass819 else:820 assert False821822 def test_connection_error_with_safe_mode(self):823 config = {'safe_mode': True}824 r = get('http://localhost:1/nope', allow_redirects=False, config=config)825 assert r.content == None826827828 # def test_invalid_content(self):829 # # WARNING: if you're using a terrible DNS provider (comcast),830 # # this will fail.831 # try:
201 unmodified lines