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


Python auth.HTTPProxyAuth方法代碼示例

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


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

示例1: _to_server

# 需要導入模塊: from requests import auth [as 別名]
# 或者: from requests.auth import HTTPProxyAuth [as 別名]
def _to_server(self, logVal):
        if self.conf['protocol'] != None:
            c_url = self.conf['protocol'] + "://" + self.conf['address'] + ":" + str(self.conf['port'])
        else:
            c_url = self.conf['address'] + ":" + str(self.conf['port'])
        utils.ilog(self.LOG_CLASS, "Sending json to: " + c_url)
        headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36"}
        if 'use_proxy' in list(self.conf.keys()) and self.conf['use_proxy'] is True:
            if "proxy_auth" in list(self.conf.keys()):
                cauth = HTTPProxyAuth(self.conf['proxy_auth']['username'], self.conf['proxy_auth']['password'])
                r = requests.put(c_url, json=logVal, proxies=self.conf['proxies'], auth = cauth, headers = headers)
            else:
                r = requests.put(c_url, json=logVal, proxies=self.conf['proxies'], headers = headers)
        else:
            r = requests.put(c_url, json=logVal, headers = headers)
        utils.ilog(self.LOG_CLASS, "Status Code: " + str(r.status_code), imp = True) 
開發者ID:fresearchgroup,項目名稱:Collaboration-System,代碼行數:18,代碼來源:eventlogger.py

示例2: _handle_basic_auth_407

# 需要導入模塊: from requests import auth [as 別名]
# 或者: from requests.auth import HTTPProxyAuth [as 別名]
def _handle_basic_auth_407(self, r, kwargs):
        if self.pos is not None:
            r.request.body.seek(self.pos)

        r.content
        r.raw.release_conn()
        prep = r.request.copy()
        if not hasattr(prep, '_cookies'):
            prep._cookies = cookies.RequestsCookieJar()
        cookies.extract_cookies_to_jar(prep._cookies, r.request, r.raw)
        prep.prepare_cookies(prep._cookies)

        self.proxy_auth = auth.HTTPProxyAuth(self.proxy_username,
                                             self.proxy_password)
        prep = self.proxy_auth(prep)
        _r = r.connection.send(prep, **kwargs)
        _r.history.append(r)
        _r.request = prep

        return _r 
開發者ID:alfa-addon,項目名稱:addon,代碼行數:22,代碼來源:guess.py

示例3: test_post_init_proxy_auth

# 需要導入模塊: from requests import auth [as 別名]
# 或者: from requests.auth import HTTPProxyAuth [as 別名]
def test_post_init_proxy_auth(self):
        """Set proxy auth info after constructing PACSession, and ensure that PAC proxy URLs then reflect it."""
        sess = PACSession(pac=PACFile(proxy_pac_js_tpl % 'PROXY a:80;'))
        with _patch_request_base() as request:
            sess.get(arbitrary_url)  # Prime proxy resolver state.
            request.assert_has_calls([
                get_call(arbitrary_url, 'http://a:80'),
            ])

        sess.proxy_auth = HTTPProxyAuth('user', 'pwd')
        with _patch_request_base() as request:
            sess.get(arbitrary_url)
            request.assert_has_calls([
                get_call(arbitrary_url, 'http://user:pwd@a:80'),
            ]) 
開發者ID:carsonyl,項目名稱:pypac,代碼行數:17,代碼來源:test_api.py

示例4: alert

# 需要導入模塊: from requests import auth [as 別名]
# 或者: from requests.auth import HTTPProxyAuth [as 別名]
def alert(self, matches):
        body = '⚠ *%s* ⚠ ```\n' % (self.create_title(matches))
        for match in matches:
            body += str(BasicMatchString(self.rule, match))
            # Separate text of aggregated alerts with dashes
            if len(matches) > 1:
                body += '\n----------------------------------------\n'
        if len(body) > 4095:
            body = body[0:4000] + "\n⚠ *message was cropped according to telegram limits!* ⚠"
        body += ' ```'

        headers = {'content-type': 'application/json'}
        # set https proxy, if it was provided
        proxies = {'https': self.telegram_proxy} if self.telegram_proxy else None
        auth = HTTPProxyAuth(self.telegram_proxy_login, self.telegram_proxy_password) if self.telegram_proxy_login else None
        payload = {
            'chat_id': self.telegram_room_id,
            'text': body,
            'parse_mode': 'markdown',
            'disable_web_page_preview': True
        }

        try:
            response = requests.post(self.url, data=json.dumps(payload, cls=DateTimeEncoder), headers=headers, proxies=proxies, auth=auth)
            warnings.resetwarnings()
            response.raise_for_status()
        except RequestException as e:
            raise EAException("Error posting to Telegram: %s. Details: %s" % (e, "" if e.response is None else e.response.text))

        elastalert_logger.info(
            "Alert sent to Telegram room %s" % self.telegram_room_id) 
開發者ID:Yelp,項目名稱:elastalert,代碼行數:33,代碼來源:alerts.py


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