How to use requests3 - 10 common examples

To help you get started, we’ve selected a few requests3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github psf / requests / tests / test_requests.py View on Github external
            CaseInsensitiveDict(FOO='foo', BAr='bar'),
        ),
    )
    def test_init(self, cid):
        assert len(cid) == 2
        assert 'foo' in cid
        assert 'bar' in cid
github psf / requests / tests / test_requests.py View on Github external
def test_non_str_basicauth(self, username, password):
        """Ensure we only allow string or bytes values for basicauth"""
        with pytest.raises(TypeError) as e:
            requests.auth._basic_auth_str(username, password)
        assert 'must be of type str or bytes' in str(e)
github psf / requests / tests / test_requests.py View on Github external
def tell(self):
                return 0

            def __iter__(self):
                return

        data = BadFileObj('the data')

        prep = requests.Request(
            'GET', 'http://example.com', data=data
        ).prepare(
        )
        assert prep._body_position == 0
        with pytest.raises(UnrewindableBodyError) as e:
            requests.utils.rewind_body(prep)
        assert 'Unable to rewind request body' in str(e)
github psf / requests / tests / test_requests.py View on Github external
def test_non_prepared_request_error(self, s):
        req = requests.Request(u('POST'), '/')
        with pytest.raises(ValueError) as e:
            s.send(req)
        assert str(e.value) == 'You can only send PreparedRequests.'
github psf / requests / tests / test_requests.py View on Github external
def test_http_error(self):
        error = requests.exceptions.HTTPError()
        assert not error.response
        response = requests.Response()
        error = requests.exceptions.HTTPError(response=response)
        assert error.response == response
        error = requests.exceptions.HTTPError('message', response=response)
        assert str(error) == 'message'
        assert error.response == response
github psf / requests / tests / test_requests.py View on Github external
def tell(self):
                raise OSError()

            def __iter__(self):
                return

        data = BadFileObj('the data')
        prep = requests.Request(
            'GET', 'http://example.com', data=data
        ).prepare(
        )
        assert prep._body_position is not None
        with pytest.raises(UnrewindableBodyError) as e:
            requests.utils.rewind_body(prep)
        assert 'Unable to rewind request body' in str(e)
github psf / requests / tests / test_requests.py View on Github external
def test_urllib3_pool_connection_closed(httpbin, s):
    s.mount('http://', HTTPAdapter(pool_connections=0, pool_maxsize=0))
    try:
        s.get(httpbin('status/200'))
    except ConnectionError as e:
        assert u"Pool is closed." in str(e)
github psf / requests / tests / test_requests.py View on Github external
def test_update_retains_unchanged(self):
        cid = CaseInsensitiveDict({'foo': 'foo', 'bar': 'bar'})
        cid.update({'foo': 'newfoo'})
        assert cid['bar'] == 'bar'
github psf / requests / tests / test_requests.py View on Github external
def test_preserve_key_case(self):
        cid = CaseInsensitiveDict(
            {'Accept': 'application/json', 'user-Agent': 'requests'}
        )
        keyset = frozenset(['Accept', 'user-Agent'])
        assert frozenset(i[0] for i in cid.items()) == keyset
        assert frozenset(cid.keys()) == keyset
        assert frozenset(cid) == keyset
github psf / requests / tests / test_requests.py View on Github external
def test_setdefault(self):
        cid = CaseInsensitiveDict({'Spam': 'blueval'})
        assert cid.setdefault('spam', 'notblueval') == 'blueval'
        assert cid.setdefault('notspam', 'notblueval') == 'notblueval'