(self, request, **kwargs)
return r
Send a given PreparedRequest.
Send a given PreparedRequest.
Send a given PreparedRequest .
def send(self, request, **kwargs):
        """Send a given PreparedRequest."""
        # Set defaults that the hooks can utilize to ensure they always have
        # the correct parameters to reproduce the previous request.
        kwargs.setdefault('stream', self.stream)
        kwargs.setdefault('verify', self.verify)
        kwargs.setdefault('cert', self.cert)
        kwargs.setdefault('proxies', self.proxies)

        # It's possible that users might accidentally send a Request object.
        # Guard against that specific failure case.
        if not isinstance(request, PreparedRequest):
            raise ValueError('You can only send PreparedRequests.')

        checked_urls = set()
        while request.url in self.redirect_cache:
            checked_urls.add(request.url)
            new_url = self.redirect_cache.get(request.url)
            if new_url in checked_urls:
                break
            request.url = new_url

        # Set up variables needed for resolve_redirects and dispatching of hooks
        allow_redirects = kwargs.pop('allow_redirects', True)
        stream = kwargs.get('stream')
        hooks = request.hooks

        # Get the appropriate adapter to use
        adapter = self.get_adapter(url=request.url)

        # Start time (approximately) of the request
        start = datetime.utcnow()

        # Send the request
        r = adapter.send(request, **kwargs)

        # Total elapsed time of the request (approximately)
        r.elapsed = datetime.utcnow() - start

        # Response manipulation hooks
        r = dispatch_hook('response', hooks, r, **kwargs)

        # Persist cookies
        if r.history:

            # If the hooks create history then we want those cookies too
            for resp in r.history:
                extract_cookies_to_jar(self.cookies, resp.request, resp.raw)

        extract_cookies_to_jar(self.cookies, request, r.raw)

        # Redirect resolving generator.
        gen = self.resolve_redirects(r, request, **kwargs)

        # Resolve redirects if allowed.
        history = [resp for resp in gen] if allow_redirects else []

        # Shuffle things around if there's history.
        if history:
            # Insert the first (original) request at the start
            history.insert(0, r)
            # Get the last request made
            r = history.pop()
            r.history = history

        if not stream:
            r.content

        return r
def send ( self , request , * * kwargs ) : # Set defaults that the hooks can utilize to ensure they always have # the correct parameters to reproduce the previous request. kwargs . setdefault ( 'stream' , self . stream ) kwargs . setdefault ( 'verify' , self . verify ) kwargs . setdefault ( 'cert' , self . cert ) kwargs . setdefault ( 'proxies' , self . proxies ) # It's possible that users might accidentally send a Request object. # Guard against that specific failure case. if not isinstance ( request , PreparedRequest ) : raise ValueError ( 'You can only send PreparedRequests.' ) checked_urls = set ( ) while request . url in self . redirect_cache : checked_urls . add ( request . url ) new_url = self . redirect_cache . get ( request . url ) if new_url in checked_urls : break request . url = new_url # Set up variables needed for resolve_redirects and dispatching of hooks allow_redirects = kwargs . pop ( 'allow_redirects' , True ) stream = kwargs . get ( 'stream' ) hooks = request . hooks # Get the appropriate adapter to use adapter = self . get_adapter ( url = request . url ) # Start time (approximately) of the request start = datetime . utcnow ( ) # Send the request r = adapter . send ( request , * * kwargs ) # Total elapsed time of the request (approximately) r . elapsed = datetime . utcnow ( ) - start # Response manipulation hooks r = dispatch_hook ( 'response' , hooks , r , * * kwargs ) # Persist cookies if r . history : # If the hooks create history then we want those cookies too for resp in r . history : extract_cookies_to_jar ( self . cookies , resp . request , resp . raw ) extract_cookies_to_jar ( self . cookies , request , r . raw ) # Redirect resolving generator. gen = self . resolve_redirects ( r , request , * * kwargs ) # Resolve redirects if allowed. history = [ resp for resp in gen ] if allow_redirects else [ ] # Shuffle things around if there's history. if history : # Insert the first (original) request at the start history . insert ( 0 , r ) # Get the last request made r = history . pop ( ) r . history = history if not stream : r . content return r