当前位置: 首页>>代码示例>>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;未经允许,请勿转载。