RequestException, Timeout, URLRequired,
TooManyRedirects, HTTPError, ConnectionError
)
+
+# Set default logging handler to avoid "No handler found" warnings.
+import logging
+try: # Python 2.7+
+ from logging import NullHandler
+except ImportError:
+ class NullHandler(logging.Handler):
+ def emit(self, record):
+ pass
+
+logging.getLogger(__name__).addHandler(NullHandler())
import os
import socket
import collections
+import logging
+
from datetime import datetime
from io import BytesIO
REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)
CONTENT_CHUNK_SIZE = 10 * 1024
+log = logging.getLogger(__name__)
class Request(object):
"""The :class:`Request <Request>` object. It carries out all functionality
self.__dict__.update(r.__dict__)
# Logging
- if self.config.get('verbose'):
- self.config.get('verbose').write('%s %s %s\n' % (
- datetime.now().isoformat(), self.method, url
- ))
+ log.info('Sending %s: %s' % (self, url))
# Use .netrc auth if none was provided.
if not self.auth and self.config.get('trust_env'):
insecure_cookies_sent = json.loads(insecure_resp.text)['cookies']
self.assertEqual(insecure_cookies_sent, {})
- def test_disabled_cookie_persistence(self):
- """Test that cookies are not persisted when configured accordingly."""
-
- config = {'store_cookies': False}
-
- # Check the case when no cookie is passed as part of the request and the one in response is ignored
- cookies = requests.get(httpbin('cookies', 'set', 'key', 'value'), config=config).cookies
- self.assertTrue(cookies.get("key") is None)
-
- # Test that the cookies passed while making the request still gets used and is available in response object.
- # only the ones received from server is not saved
- cookies_2 = requests.get(httpbin('cookies', 'set', 'key', 'value'), config=config,\
- cookies={"key_2": "value_2"}).cookies
- self.assertEqual(len(cookies_2), 1)
- self.assertEqual(cookies_2.get("key_2"), "value_2")
-
- # Use the session and make sure that the received cookie is not used in subsequent calls
- s = requests.session()
- s.get(httpbin('cookies', 'set', 'key', 'value'), config=config)
- r = s.get(httpbin('cookies'))
- self.assertEqual(json.loads(r.text)['cookies'], {})
-
def test_jar_utility_functions(self):
"""Test utility functions such as list_domains, list_paths, multiple_domains."""
r = requests.get("http://github.com")