From fae670147814f7107f6978117948b8395030a522 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 9 Dec 2016 08:39:49 -0600 Subject: [PATCH] Add deprecation warnings for 3.0 Add extra test parameter for basic auth encoding --- requests/auth.py | 15 +++++++++++++++ tests/test_requests.py | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/requests/auth.py b/requests/auth.py index bd2fe7d8..701104d0 100644 --- a/requests/auth.py +++ b/requests/auth.py @@ -12,6 +12,7 @@ import re import time import hashlib import threading +import warnings from base64 import b64encode @@ -36,9 +37,23 @@ def _basic_auth_str(username, password): # These are here solely to maintain backwards compatibility # for things like ints. This will be removed in 3.0.0. if not isinstance(username, basestring): + warnings.warn( + "Non-string usernames will no longer be supported in Requests " + "3.0.0. Please convert the object you've passed in ({!r}) to " + "a string or bytes object in the near future to avoid " + "problems.".format(username), + category=DeprecationWarning, + ) username = str(username) if not isinstance(password, basestring): + warnings.warn( + "Non-string passwords will no longer be supported in Requests " + "3.0.0. Please convert the object you've passed in ({!r}) to " + "a string or bytes object in the near future to avoid " + "problems.".format(password), + category=DeprecationWarning, + ) password = str(password) # -- End Removal -- diff --git a/tests/test_requests.py b/tests/test_requests.py index 211296dd..b0cb7d6b 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -484,7 +484,8 @@ class TestRequests: 'username, password', ( ('user', 'pass'), (u'имя'.encode('utf-8'), u'пароль'.encode('utf-8')), - (42, 42) + (42, 42), + (None, None), )) def test_set_basicauth(self, httpbin, username, password): auth = (username, password)