# Buggy code
def request(
    self,
    method,
    url,
    params=None,
    data=None,
    headers=None,
    cookies=None,
    files=None,
    auth=None,
    timeout=None,
    allow_redirects=True,
    proxies=None,
    hooks=None,
    stream=None,
    verify=None,
    cert=None,
):
    """Constructs a :class:`Request <Request>`, prepares it and sends it.
    Returns :class:`Response <Response>` object.

    :param method: method for the new :class:`Request` object.
    :param url: URL for the new :class:`Request` object.
    :param params: (optional) Dictionary or bytes to be sent in the query
        string for the :class:`Request`.
    :param data: (optional) Dictionary or bytes to send in the body of the
        :class:`Request`.
    :param headers: (optional) Dictionary of HTTP Headers to send with the
        :class:`Request`.
    :param cookies: (optional) Dict or CookieJar object to send with the
        :class:`Request`.
    :param files: (optional) Dictionary of 'filename': file-like-objects
        for multipart encoding upload.
    :param auth: (optional) Auth tuple or callable to enable
        Basic/Digest/Custom HTTP Auth.
    :param timeout: (optional) Float describing the timeout of the
        request.
    :param allow_redirects: (optional) Boolean. Set to True by default.
    :param proxies: (optional) Dictionary mapping protocol to the URL of
        the proxy.
    :param stream: (optional) whether to immediately download the response
        content. Defaults to ``False``.
    :param verify: (optional) if ``True``, the SSL cert will be verified.
        A CA_BUNDLE path can also be provided.
    :param cert: (optional) if String, path to ssl client cert file (.pem).
        If Tuple, ('cert', 'key') pair.
    """

    method = builtin_str(method)

    # Create the Request.
    req = Request(
        method=method.upper(),
        url=url,
        headers=headers,
        files=files,
        data=data or {},
        params=params or {},
        auth=auth,
        cookies=cookies,
        hooks=hooks,
    )
    prep = self.prepare_request(req)

    # Add param cookies to session cookies
    self.cookies = cookiejar_from_dict(cookies, cookiejar=self.cookies, overwrite=False)

    proxies = proxies or {}

    # Gather clues from the surrounding environment.
    if self.trust_env:
        # Set environment's proxies.
        env_proxies = get_environ_proxies(url) or {}
        for k, v in env_proxies.items():
            proxies.setdefault(k, v)

        # Look for configuration.
        if not verify and verify is not False:
            verify = os.environ.get("REQUESTS_CA_BUNDLE")

        # Curl compatibility.
        if not verify and verify is not False:
            verify = os.environ.get("CURL_CA_BUNDLE")

    # Merge all the kwargs.
    proxies = merge_setting(proxies, self.proxies)
    stream = merge_setting(stream, self.stream)
    verify = merge_setting(verify, self.verify)
    cert = merge_setting(cert, self.cert)

    # Send the request.
    send_kwargs = {
        "stream": stream,
        "timeout": timeout,
        "verify": verify,
        "cert": cert,
        "proxies": proxies,
        "allow_redirects": allow_redirects,
    }
    resp = self.send(prep, **send_kwargs)

    return resp


# Traceback (AttributeError)
Traceback (most recent call last):
File "rtest.py", line 16, in <module>
requests.get(URL, cookies=cookiejar)
File "/tmp/rtestenv/lib/python2.7/site-packages/requests/api.py", line 55, in get
return request('get', url, **kwargs)
File "/tmp/rtestenv/lib/python2.7/site-packages/requests/api.py", line 44, in request
return session.request(method=method, url=url, **kwargs)
File "/tmp/rtestenv/lib/python2.7/site-packages/requests/sessions.py", line 327, in request
self.cookies = cookiejar_from_dict(cookies, cookiejar=self.cookies, overwrite=False)
File "/tmp/rtestenv/lib/python2.7/site-packages/requests/cookies.py", line 410, in cookiejar_from_dict
cookiejar.set_cookie(create_cookie(name, cookie_dict[name]))
AttributeError: MozillaCookieJar instance has no attribute '__getitem__'

# Fixed code
def request(
    self,
    method,
    url,
    params=None,
    data=None,
    headers=None,
    cookies=None,
    files=None,
    auth=None,
    timeout=None,
    allow_redirects=True,
    proxies=None,
    hooks=None,
    stream=None,
    verify=None,
    cert=None,
):
    """Constructs a :class:`Request <Request>`, prepares it and sends it.
    Returns :class:`Response <Response>` object.

    :param method: method for the new :class:`Request` object.
    :param url: URL for the new :class:`Request` object.
    :param params: (optional) Dictionary or bytes to be sent in the query
        string for the :class:`Request`.
    :param data: (optional) Dictionary or bytes to send in the body of the
        :class:`Request`.
    :param headers: (optional) Dictionary of HTTP Headers to send with the
        :class:`Request`.
    :param cookies: (optional) Dict or CookieJar object to send with the
        :class:`Request`.
    :param files: (optional) Dictionary of 'filename': file-like-objects
        for multipart encoding upload.
    :param auth: (optional) Auth tuple or callable to enable
        Basic/Digest/Custom HTTP Auth.
    :param timeout: (optional) Float describing the timeout of the
        request.
    :param allow_redirects: (optional) Boolean. Set to True by default.
    :param proxies: (optional) Dictionary mapping protocol to the URL of
        the proxy.
    :param stream: (optional) whether to immediately download the response
        content. Defaults to ``False``.
    :param verify: (optional) if ``True``, the SSL cert will be verified.
        A CA_BUNDLE path can also be provided.
    :param cert: (optional) if String, path to ssl client cert file (.pem).
        If Tuple, ('cert', 'key') pair.
    """

    method = builtin_str(method)

    # Create the Request.
    req = Request(
        method=method.upper(),
        url=url,
        headers=headers,
        files=files,
        data=data or {},
        params=params or {},
        auth=auth,
        cookies=cookies,
        hooks=hooks,
    )
    prep = self.prepare_request(req)

    # Add param cookies to session cookies
    if isinstance(cookies, dict):
        self.cookies = cookiejar_from_dict(
            cookies, cookiejar=self.cookies, overwrite=False
        )
    elif isinstance(cookies, cookielib.CookieJar):
        self.cookies.update(cookies)

    proxies = proxies or {}

    # Gather clues from the surrounding environment.
    if self.trust_env:
        # Set environment's proxies.
        env_proxies = get_environ_proxies(url) or {}
        for k, v in env_proxies.items():
            proxies.setdefault(k, v)

        # Look for configuration.
        if not verify and verify is not False:
            verify = os.environ.get("REQUESTS_CA_BUNDLE")

        # Curl compatibility.
        if not verify and verify is not False:
            verify = os.environ.get("CURL_CA_BUNDLE")

    # Merge all the kwargs.
    proxies = merge_setting(proxies, self.proxies)
    stream = merge_setting(stream, self.stream)
    verify = merge_setting(verify, self.verify)
    cert = merge_setting(cert, self.cert)

    # Send the request.
    send_kwargs = {
        "stream": stream,
        "timeout": timeout,
        "verify": verify,
        "cert": cert,
        "proxies": proxies,
        "allow_redirects": allow_redirects,
    }
    resp = self.send(prep, **send_kwargs)

    return resp