当前位置: 首页>>代码示例>>Python>>正文


Python request.get_method方法代码示例

本文整理汇总了Python中urllib.request.get_method方法的典型用法代码示例。如果您正苦于以下问题:Python request.get_method方法的具体用法?Python request.get_method怎么用?Python request.get_method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib.request的用法示例。


在下文中一共展示了request.get_method方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: check_connection

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def check_connection(self):
        request = urllib.request.Request(self._api_hostname)
        request.get_method = lambda: 'GET'

        try:
            data = self._request('/api/v1/service-online', {}, force=True)
        except URLError as e:
            TestLogger.log_warning('Problem with connecting to {} ({}).'.format(self._api_hostname, e))
            return
        else:
            self._has_connection = (
                200 >= self._last_response.status < 400
            ) and data.get('success')
            if data.get('msg'):
                TestLogger.log_warning(data.get('msg'))
            self.version = data.get('version') 
开发者ID:thejoeejoee,项目名称:VUT-FIT-IFJ-2017-toolkit,代码行数:18,代码来源:uploader.py

示例2: put

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def put(self, location, params=None):
        """Dispatch a PUT request to a SeaMicro chassis.

        The seamicro box has order-dependent HTTP parameters, so we build
        our own get URL, and use a list vs. a dict for data, as the order is
        implicit.
        """
        opener = urllib.request.build_opener(urllib.request.HTTPHandler)
        url = self.build_url(location, params)
        request = urllib.request.Request(url)
        request.get_method = lambda: "PUT"
        request.add_header("content-type", "text/json")
        response = opener.open(request)
        json_data = self.parse_response(url, response)

        return json_data["result"] 
开发者ID:maas,项目名称:maas,代码行数:18,代码来源:seamicro.py

示例3: OpenWebRequest

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def OpenWebRequest(uri, post_data, headers, timeout, get_method=None):
    request = urllib.request.Request(uri, post_data, headers)
    if get_method:
        request.get_method = get_method
    if timeout == 0:
        response = urllib.request.urlopen(request)
    else:
        response = urllib.request.urlopen(request, timeout=timeout)
    return response 
开发者ID:rapid7,项目名称:nexpose-client-python,代码行数:11,代码来源:nexpose.py

示例4: ExecuteWebRequest

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def ExecuteWebRequest(uri, post_data, headers, timeout, get_method=None):
    response = OpenWebRequest(uri, post_data, headers, timeout, get_method)
    return response.read().decode('utf-8') 
开发者ID:rapid7,项目名称:nexpose-client-python,代码行数:5,代码来源:nexpose.py

示例5: ExecuteWithPostData_JSON

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def ExecuteWithPostData_JSON(session_id, uri, sub_url, timeout, post_data, get_method):
    headers = CreateHeadersWithSessionCookieAndCustomHeader(session_id)
    headers["Content-Type"] = "application/json; charset=UTF-8"
    if isinstance(post_data, dict) or isinstance(post_data, list):
        post_data = json.dumps(post_data, separators=(',', ':'))
    post_data = post_data.encode('utf-8')
    return ExecuteWebRequest(uri + sub_url, post_data, headers, timeout, get_method) 
开发者ID:rapid7,项目名称:nexpose-client-python,代码行数:9,代码来源:nexpose.py

示例6: check_target

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def check_target(target, options):
    '''
    Just put a protocol to a valid IP and check if connection works,
    returning HEAD response
    '''
    # Recover used options
    ssldisabled = options.ssldisabled
    useget = options.useget
    proxy = options.proxy
    response = None

    target = normalize(target)

    try:
        request = urllib.request.Request(target, headers=client_headers)

        # Set method
        method = 'GET' if useget else 'HEAD'
        request.get_method = lambda: method

        # Set proxy
        set_proxy(proxy)
        # Set certificate validation 
        if ssldisabled:
            context = get_unsafe_context()
            response = urllib.request.urlopen(request, timeout=10, context=context)
        else:
            response = urllib.request.urlopen(request, timeout=10)

    except Exception as e:
        print_error(e)
        sys.exit(1)

    if response is not None:
        return response
    print("Couldn't read a response from server.")
    sys.exit(3) 
开发者ID:meliot,项目名称:shcheck,代码行数:39,代码来源:shcheck.py

示例7: open_request

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def open_request(url, query_params=None, user_agent=None, post_data=None, referer=None, get_method=None, cookies=False,
                 timeout=None, headers=None, **kwargs):
    if query_params is None:
        query_params = {}

    if user_agent is None:
        user_agent = ua_cloudbot

    query_params.update(kwargs)

    url = prepare_url(url, query_params)

    request = urllib.request.Request(url, post_data)

    if get_method is not None:
        request.get_method = lambda: get_method

    if headers is not None:
        for header_key, header_value in headers.items():
            request.add_header(header_key, header_value)

    request.add_header('User-Agent', user_agent)

    if referer is not None:
        request.add_header('Referer', referer)

    if cookies:
        opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar))
    else:
        opener = urllib.request.build_opener()

    if timeout:
        return opener.open(request, timeout=timeout)

    return opener.open(request)


# noinspection PyShadowingBuiltins 
开发者ID:TotallyNotRobots,项目名称:CloudBot,代码行数:40,代码来源:http.py

示例8: open

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def open(url, query_params=None, user_agent=None, post_data=None,
         referer=None, get_method=None, cookies=False, timeout=None, headers=None,
         **kwargs):  # pylint: disable=locally-disabled, redefined-builtin  # pragma: no cover
    warnings.warn(
        "http.open() is deprecated, use http.open_request() instead.",
        DeprecationWarning
    )

    return open_request(
        url, query_params=query_params, user_agent=user_agent, post_data=post_data, referer=referer,
        get_method=get_method, cookies=cookies, timeout=timeout, headers=headers, **kwargs
    ) 
开发者ID:TotallyNotRobots,项目名称:CloudBot,代码行数:14,代码来源:http.py

示例9: test_default_values

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def test_default_values(self):
        Request = urllib.request.Request
        request = Request("http://www.python.org")
        self.assertEqual(request.get_method(), 'GET')
        request = Request("http://www.python.org", {})
        self.assertEqual(request.get_method(), 'POST') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:8,代码来源:test_urllib.py

示例10: test_with_method_arg

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def test_with_method_arg(self):
        Request = urllib.request.Request
        request = Request("http://www.python.org", method='HEAD')
        self.assertEqual(request.method, 'HEAD')
        self.assertEqual(request.get_method(), 'HEAD')
        request = Request("http://www.python.org", {}, method='HEAD')
        self.assertEqual(request.method, 'HEAD')
        self.assertEqual(request.get_method(), 'HEAD')
        request = Request("http://www.python.org", method='GET')
        self.assertEqual(request.get_method(), 'GET')
        request.method = 'HEAD'
        self.assertEqual(request.get_method(), 'HEAD') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_urllib.py

示例11: get_method

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def get_method(self):
        """Return a string indicating the HTTP request method."""
        default_method = "POST" if self.data is not None else "GET"
        return getattr(self, 'method', default_method) 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:6,代码来源:request.py

示例12: redirect_request

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def redirect_request(self, req, fp, code, msg, headers, newurl):
        """Return a Request or None in response to a redirect.

        This is called by the http_error_30x methods when a
        redirection response is received.  If a redirection should
        take place, return a new Request to allow http_error_30x to
        perform the redirect.  Otherwise, raise HTTPError if no-one
        else should try to handle this url.  Return None if you can't
        but another Handler might.
        """
        m = req.get_method()
        if (not (code in (301, 302, 303, 307) and m in ("GET", "HEAD")
            or code in (301, 302, 303) and m == "POST")):
            raise HTTPError(req.full_url, code, msg, headers, fp)

        # Strictly (according to RFC 2616), 301 or 302 in response to
        # a POST MUST NOT cause a redirection without confirmation
        # from the user (of urllib.request, in this case).  In practice,
        # essentially all clients do redirect in this case, so we do
        # the same.

        # Be conciliant with URIs containing a space.  This is mainly
        # redundant with the more complete encoding done in http_error_302(),
        # but it is kept for compatibility with other callers.
        newurl = newurl.replace(' ', '%20')

        CONTENT_HEADERS = ("content-length", "content-type")
        newheaders = {k: v for k, v in req.headers.items()
                      if k.lower() not in CONTENT_HEADERS}
        return Request(newurl,
                       headers=newheaders,
                       origin_req_host=req.origin_req_host,
                       unverifiable=True)

    # Implementation note: To avoid the server sending us into an
    # infinite loop, the request object needs to track what URLs we
    # have already seen.  Do this by adding a handler-specific
    # attribute to the Request object. 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:40,代码来源:request.py

示例13: _get_content_length

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def _get_content_length(self, request):
        return http.client.HTTPConnection._get_content_length(
            request.data,
            request.get_method()) 
开发者ID:CedricGuillemet,项目名称:Imogen,代码行数:6,代码来源:request.py

示例14: _http_response

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def _http_response(self, request, response):
        fetch = {
            'url': request.full_url,
            'method': request.get_method(),
            'response_code': response.code,
            'response_headers': response.headers,
        }
        self.fetches.append(fetch)
        return response 
开发者ID:internetarchive,项目名称:brozzler,代码行数:11,代码来源:ydl.py

示例15: check_url

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import get_method [as 别名]
def check_url(url,ua):
    global total_requests
    total_requests += 1
    request = urllib.request.Request(url)
    request.add_header('User-Agent', ua)
    request.get_method = lambda: 'HEAD'
    try:
        urllib.request.urlopen(request)
        return '1'
    except urllib.request.HTTPError:
        return '0' 
开发者ID:Tuhinshubhra,项目名称:CMSeeK,代码行数:13,代码来源:basic.py


注:本文中的urllib.request.get_method方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。