當前位置: 首頁>>代碼示例>>Python>>正文


Python cookies.cookiejar_from_dict方法代碼示例

本文整理匯總了Python中requests.cookies.cookiejar_from_dict方法的典型用法代碼示例。如果您正苦於以下問題:Python cookies.cookiejar_from_dict方法的具體用法?Python cookies.cookiejar_from_dict怎麽用?Python cookies.cookiejar_from_dict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在requests.cookies的用法示例。


在下文中一共展示了cookies.cookiejar_from_dict方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _set_cookies_for_request

# 需要導入模塊: from requests import cookies [as 別名]
# 或者: from requests.cookies import cookiejar_from_dict [as 別名]
def _set_cookies_for_request(session, request_args):
    """
    Possibly reset session cookies for a single request then set them back.
    If no cookies were present in the request arguments, do nothing.

    This does not use try/finally because if it fails then we don't care about
    the cookies anyway

    Args:
        session (requests.Session): Current session
        request_args (dict): current request arguments
    """
    if "cookies" in request_args:
        old_cookies = dict_from_cookiejar(session.cookies)
        session.cookies = cookiejar_from_dict({})
        yield
        session.cookies = cookiejar_from_dict(old_cookies)
    else:
        yield 
開發者ID:taverntesting,項目名稱:tavern,代碼行數:21,代碼來源:request.py

示例2: __init__

# 需要導入模塊: from requests import cookies [as 別名]
# 或者: from requests.cookies import cookiejar_from_dict [as 別名]
def __init__(self, response):
        super(SanitizedResponse, self).__init__()
        self.status_code = response.status_code
        self.encoding = response.encoding
        self.raw = response.raw
        self.reason = response.reason
        self.url = response.url
        self.request = response.request
        self.connection = response.connection
        self._content_consumed = True

        self._content = ""
        self.cookies = cookiejar_from_dict({})
        self.headers = CaseInsensitiveDict()
        self.headers['content-length'] = '0'
        for header in ('date', 'server'):
            if header in response.headers:
                self.headers[header] = response.headers[header] 
開發者ID:pythongssapi,項目名稱:requests-gssapi,代碼行數:20,代碼來源:gssapi_.py

示例3: __init__

# 需要導入模塊: from requests import cookies [as 別名]
# 或者: from requests.cookies import cookiejar_from_dict [as 別名]
def __init__(self, token_v2, monitor=False, start_monitoring=False, enable_caching=False, cache_key=None):
        self.session = create_session()
        self.session.cookies = cookiejar_from_dict({"token_v2": token_v2})
        if enable_caching:
            cache_key = cache_key or hashlib.sha256(token_v2.encode()).hexdigest()
            self._store = RecordStore(self, cache_key=cache_key)
        else:
            self._store = RecordStore(self)
        if monitor:
            self._monitor = Monitor(self)
            if start_monitoring:
                self.start_monitoring()
        else:
            self._monitor = None
        self._update_user_info() 
開發者ID:jamalex,項目名稱:notion-py,代碼行數:17,代碼來源:client.py

示例4: _hello

# 需要導入模塊: from requests import cookies [as 別名]
# 或者: from requests.cookies import cookiejar_from_dict [as 別名]
def _hello(self):
        log.debug('_hello ...')

        # a new session is required for the app_token
        self.session.http.cookies = cookiejar_from_dict({})
        if self.base_url == 'https://zattoo.com':
            app_token_url = 'https://zattoo.com/int/'
        else:
            app_token_url = self.base_url
        res = self.session.http.get(app_token_url)
        match = self._app_token_re.search(res.text)

        app_token = match.group(1)
        hello_url = self.API_HELLO.format(self.base_url)

        if self._uuid:
            __uuid = self._uuid
        else:
            __uuid = str(uuid.uuid4())
            self._session_attributes.set(
                'uuid', __uuid, expires=self.TIME_SESSION)

        params = {
            'client_app_token': app_token,
            'uuid': __uuid,
            'lang': 'en',
            'format': 'json'
        }
        res = self.session.http.post(hello_url, headers=self.headers, data=params) 
開發者ID:streamlink,項目名稱:streamlink,代碼行數:31,代碼來源:zattoo.py

示例5: _initialize

# 需要導入模塊: from requests import cookies [as 別名]
# 或者: from requests.cookies import cookiejar_from_dict [as 別名]
def _initialize(self):
        """
        .. warning: Called automatically by GoLismero. Do not call!
        """

        # Start a new session.
        self.__session = Session()

        # Load the proxy settings.
        proxy_addr = Config.audit_config.proxy_addr
        if proxy_addr:
            proxy_port = Config.audit_config.proxy_port
            if proxy_port:
                proxy_addr = "%s:%s" % (proxy_addr, proxy_port)
            auth_user = Config.audit_config.proxy_user
            auth_pass = Config.audit_config.proxy_pass
            auth, _ = detect_auth_method(proxy_addr)
            self.__session.auth = get_auth_obj(auth, auth_user, auth_pass)
            self.__session.proxies = {
                "http":  proxy_addr,
                "https": proxy_addr,
                "ftp":   proxy_addr,
            }

        # Load the cookies.
        cookie = Config.audit_config.cookie
        if cookie:
            self.__session.cookies = cookiejar_from_dict(cookie)

        # Set User Agent
        self.__user_agent = Config.audit_config.user_agent


    #-------------------------------------------------------------------------- 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:36,代碼來源:http.py

示例6: mock_response

# 需要導入模塊: from requests import cookies [as 別名]
# 或者: from requests.cookies import cookiejar_from_dict [as 別名]
def mock_response():
    def make_response(url='', content='ok', status_code=200, history=(),
                      encoding='utf8', reason='', cookies=None):
        r = Response()
        r.url = url
        r._content = content
        r.status_code = status_code
        r.history = history
        r.encoding = encoding
        r.reason = reason
        r.cookies = cookiejar_from_dict(cookies or {})
        return r

    return make_response 
開發者ID:huskar-org,項目名稱:huskar,代碼行數:16,代碼來源:test_notify.py

示例7: queueSpider

# 需要導入模塊: from requests import cookies [as 別名]
# 或者: from requests.cookies import cookiejar_from_dict [as 別名]
def queueSpider(add_link_dictionary):
    # get download information from add_link_dictionary
    for i in ['link', 'header', 'out', 'user_agent', 'load_cookies', 'referer']:
        if not (i in add_link_dictionary):
            add_link_dictionary[i] = None

    link = add_link_dictionary['link']
    header = add_link_dictionary['header']
    user_agent = add_link_dictionary['user_agent']
    raw_cookies = add_link_dictionary['load_cookies']
    referer = add_link_dictionary['referer']

    requests_session = requests.Session()  # defining a requests Session

    if raw_cookies:  # set cookies
        cookie = SimpleCookie()
        cookie.load(raw_cookies)

        cookies = {key: morsel.value for key, morsel in cookie.items()}
        requests_session.cookies = cookiejar_from_dict(cookies)

    if referer:
        # set referer to the session
        requests_session.headers.update({'referer': referer})

    if user_agent:
        # set user_agent to the session
        requests_session.headers.update({'user-agent': user_agent})

    # find headers
    try:
        response = requests_session.head(link)
        header = response.headers
    except:
        header = {}
    filename = None
    if 'Content-Disposition' in header.keys():  # checking if filename is available
        content_disposition = header['Content-Disposition']
        if content_disposition.find('filename') != -1:
            filename_splited = content_disposition.split('filename=')
            filename_splited = filename_splited[-1]
            # getting file name in desired format
            filename = filename_splited[1:-1]

    if not(filename):
        filename = link.split('/')[-1]

    return filename 
開發者ID:persepolisdm,項目名稱:persepolis,代碼行數:50,代碼來源:spider.py

示例8: addLinkSpider

# 需要導入模塊: from requests import cookies [as 別名]
# 或者: from requests.cookies import cookiejar_from_dict [as 別名]
def addLinkSpider(add_link_dictionary):
    # get user's download information from add_link_dictionary
    for i in ['link', 'header', 'out', 'user_agent', 'load_cookies', 'referer']:
        if not (i in add_link_dictionary):
            add_link_dictionary[i] = None

    link = add_link_dictionary['link']
    header = add_link_dictionary['header']
    user_agent = add_link_dictionary['user_agent']
    raw_cookies = add_link_dictionary['load_cookies']
    referer = add_link_dictionary['referer']

    requests_session = requests.Session()  # defining a requests Session

    if raw_cookies:  # set cookies
        cookie = SimpleCookie()
        cookie.load(raw_cookies)

        cookies = {key: morsel.value for key, morsel in cookie.items()}
        requests_session.cookies = cookiejar_from_dict(cookies)

    if referer:
        # set referer to the session
        requests_session.headers.update({'referer': referer})

    if user_agent:
        # set user_agent to the session
        requests_session.headers.update({'user-agent': user_agent})

    # find headers
    try:
        response = requests_session.head(link)
        header = response.headers
    except:
        header = {}

    # find file size
    file_size = None
    if 'Content-Length' in header.keys():  # checking if file_size is available
        file_size = int(header['Content-Length'])

        # converting file_size to KiB or MiB or GiB
        file_size = str(humanReadableSize(file_size))

    # find file name
    file_name = None
    if 'Content-Disposition' in header.keys():  # checking if filename is available
        content_disposition = header['Content-Disposition']
        if content_disposition.find('filename') != -1:
            filename_splited = content_disposition.split('filename=')
            filename_splited = filename_splited[-1]
            # getting file name in desired format
            file_name = str(filename_splited[1:-1])

    return file_name, file_size  # If no Content-Length ? fixed it. 
開發者ID:persepolisdm,項目名稱:persepolis,代碼行數:57,代碼來源:spider.py


注:本文中的requests.cookies.cookiejar_from_dict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。