Skip to content
Myr

Wrap socket.error in ConnectionError (+ unit tests)

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

authored by Stefan Praszalowicz · committed by Stefan Praszalowicz · parent bc7b2f9 · 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
592 unmodified lines
608 timeout=self.timeout,609 )610 self.sent = True611612 except socket.error as sockerr:613 raise ConnectionError(sockerr)614615 except MaxRetryError as e:616 raise ConnectionError(e)617618 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:
183 unmodified lines