Merge pull request #4240 from mgasvoda/master

Adding header name to exception
This commit is contained in:
Cory Benfield
2017-08-12 15:41:27 +01:00
committed by GitHub
3 changed files with 9 additions and 5 deletions
+1
View File
@@ -7,6 +7,7 @@ dev
+++
**Improvements**
- Error messages for invalid headers now include the header name for easier debugging
**Bugfixes**
+2 -2
View File
@@ -868,8 +868,8 @@ def check_header_validity(header):
if not pat.match(value):
raise InvalidHeader("Invalid return character or leading space in header: %s" % name)
except TypeError:
raise InvalidHeader("Header value %s must be of type str or bytes, "
"not %s" % (value, type(value)))
raise InvalidHeader("Value for header {%s: %s} must be of type str or "
"bytes, not %s" % (name, value, type(value)))
def urldefragauth(url):
+6 -3
View File
@@ -1401,14 +1401,17 @@ class TestRequests:
headers_list = {'baz': ['foo', 'bar']}
# Test for int
with pytest.raises(InvalidHeader):
with pytest.raises(InvalidHeader) as excinfo:
r = requests.get(httpbin('get'), headers=headers_int)
assert 'foo' in str(excinfo.value)
# Test for dict
with pytest.raises(InvalidHeader):
with pytest.raises(InvalidHeader) as excinfo:
r = requests.get(httpbin('get'), headers=headers_dict)
assert 'bar' in str(excinfo.value)
# Test for list
with pytest.raises(InvalidHeader):
with pytest.raises(InvalidHeader) as excinfo:
r = requests.get(httpbin('get'), headers=headers_list)
assert 'baz' in str(excinfo.value)
def test_header_no_return_chars(self, httpbin):
"""Ensure that a header containing return character sequences raise an