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


Python parse.urlencode方法代码示例

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


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

示例1: lmgtfy

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def lmgtfy(self, ctx: Context, *args: str):
        """
        Returns a LMGTFY URL for a given user argument.
        """
        # Creates a lmgtfy.com url for the given query.
        request_data = {
            "q": " ".join(arg for arg in args if not arg.startswith("-")),
            "ie": int("-ie" in args),
        }
        url = "https://lmgtfy.com/?" + urlencode(request_data)

        await ctx.send(url)

        if "-d" in args:
            await ctx.message.delete()

    # Ratelimit to one use per user every minute and 4 usages per minute per channel 
开发者ID:CyberDiscovery,项目名称:cyberdisc-bot,代码行数:19,代码来源:fun.py

示例2: get_subscribe_authorize_url

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def get_subscribe_authorize_url(self, scene, template_id, redirect_url, reserved=None):
        """
        构造请求用户授权的url
        详情请参阅:
        https://mp.weixin.qq.com/wiki?id=mp1500374289_66bvB

        :param scene: 订阅场景值,开发者可以填0-10000的整形值,用来标识订阅场景值
        :type scene: int
        :param template_id: 订阅消息模板ID,登录公众平台后台,在接口权限列表处可查看订阅模板ID
        :param redirect_url: 授权后重定向的回调地址
        :param reserved: 用于保持请求和回调的状态,授权请后原样带回给第三方。该参数可用于防止csrf攻击。若不指定则随机生成。
        """
        if reserved is None:
            reserved = random_string()
        base_url = "https://mp.weixin.qq.com/mp/subscribemsg"
        params = [
            ("action", "get_confirm"),
            ("appid", self.appid),
            ("scene", scene),
            ("template_id", template_id),
            ("redirect_url", redirect_url),
            ("reserved", reserved),
        ]
        encoded_params = urlencode(params)
        return f"{base_url}?{encoded_params}#wechat_redirect" 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:27,代码来源:message.py

示例3: __init__

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def __init__(
    self,
    params,
    site_api='https://maps.googleapis.com/maps/api/streetview',
    site_metadata='https://maps.googleapis.com/maps/api/streetview/metadata'):
    
    # (params) Set default params
    defaults = {
      'size': '640x640'
    }
    for i in range(len(params)):
      for k in defaults:
        if k not in params[i]:
          params[i][k] = defaults[k]
    self.params = params
    
    # (image) Create image api links from parameters
    self.links = [site_api + '?' + urlencode(p) for p in params]
    
    # (metadata) Create metadata api links and data from parameters
    self.metadata_links = [site_metadata + '?' + urlencode(p) for p in params]
    self.metadata = [requests.get(url, stream=True).json() for url in self.metadata_links] 
开发者ID:rrwen,项目名称:google_streetview,代码行数:24,代码来源:api.py

示例4: get_mood_url

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def get_mood_url(self):
        url='https://h5.qzone.qq.com/proxy/domain/taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6?'
        params = {
              "sort":0,
                  "start":0,
              "num":20,
            "cgi_host": "http://taotao.qq.com/cgi-bin/emotion_cgi_msglist_v6",
              "replynum":100,
              "callback":"_preloadCallback",
              "code_version":1,
            "inCharset": "utf-8",
            "outCharset": "utf-8",
            "notice": 0,
              "format":"jsonp",
              "need_private_comment":1,
              "g_tk": self.g_tk
              }
        url = url + parse.urlencode(params)
        return url 
开发者ID:nanxung,项目名称:QQ_zone,代码行数:21,代码来源:qq_spider.py

示例5: post

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def post(self, payload, request_par):
        data = parse.urlencode(request_par).encode()

        if self.UserAgent != None:
            req = Request(
                    self.target_url,
                    data=data, 
                    headers={"User-Agent":self.UserAgent})
            conn = urlopen(req, timeout=self.TimeOut)
        else:
            conn = urlopen(self.target_url,
                    data=data,
                    timeout=self.TimeOut)

        html = conn.read().decode("utf-8")
        page_size = len(html)

        if self.verbose == True:
            print(" [+] Source code got from %s" % payload)
            print("----START" + "-"*71)
            print(html)
            print("----END" + "-"*73)
        
        return(self.target_url, page_size, html, payload) 
开发者ID:fnk0c,项目名称:dot2moon,代码行数:26,代码来源:connection.py

示例6: test_get_uptoken

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def test_get_uptoken(self):
        params = {'bucket': 'jike'}
        success_reponse = {'uptoken': 'token'}
        responses.add(responses.GET, constants.ENDPOINTS['picture_uptoken'],
                      json=success_reponse, status=200)
        responses.add(responses.GET, constants.ENDPOINTS['picture_uptoken'],
                      status=404)
        # success call
        result = utils.get_uptoken()
        self.assertEqual(result, 'token')
        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(responses.calls[0].request.url,
                         constants.ENDPOINTS['picture_uptoken'] + '?' + urlencode(params))
        self.assertEqual(responses.calls[0].response.json(), success_reponse)
        # failed call
        with self.assertRaises(requests.HTTPError) as cm:
            utils.get_uptoken()
        self.assertEqual(len(responses.calls), 2)
        self.assertEqual(cm.exception.response.status_code, 404) 
开发者ID:Sorosliu1029,项目名称:Jike-Metro,代码行数:21,代码来源:test_utils.py

示例7: _http_request

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def _http_request(self, url: str, headers: dict = None, payload: dict = None) -> Response:
        if not self._session:
            raise RetsClientError('Session not instantiated. Call .login() first')

        request_headers = {
            **(headers or {}),
            'User-Agent': self.user_agent,
            'RETS-Version': self.rets_version,
            'RETS-UA-Authorization': self._rets_ua_authorization()
        }

        if self._use_get_method:
            if payload:
                url = '%s?%s' % (url, urlencode(payload))
            response = self._session.get(url, auth=self._http_auth, headers=request_headers)
        else:
            response = self._session.post(url, auth=self._http_auth, headers=request_headers, data=payload)

        response.raise_for_status()
        self._rets_session_id = self._session.cookies.get('RETS-Session-ID', '')
        return response 
开发者ID:opendoor-labs,项目名称:rets,代码行数:23,代码来源:client.py

示例8: _load

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def _load(self, request: Request) -> tuple:
        params = ('&' + urlencode(request.params)) if request.params else ''
        url = request.url + params
        item = self._cache.get(url, None)

        if item is None:
            return None, None

        vary_key = self._vary_key(request, item[0])
        cached = item[1].get(vary_key, None)

        if cached is not None:
            response = cached['response']
            deque_item = (url, vary_key)
            if self._cc_fresh(cached):
                self._update_usage(deque_item)
                return response, None
            elif self._has_etag(cached):
                self._update_usage(deque_item)
                return response, cached['etag']
            elif self.max_size is not None:
                self._deque.remove(deque_item)

        return None, None 
开发者ID:felix-hilden,项目名称:tekore,代码行数:26,代码来源:extending.py

示例9: stations

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def stations(self, **params):
        """Get list of US weather stations and their metadata.

        Response in this method should not be modified.
        In this way, we can keep track of changes made by NOAA through
        functional tests @todo(paulokuong) later on.

        Args:
            station_id (str[optional]): station id.
            state (str[optional]): 2 letters state code.
            limit (int[optional]): limit of results.
        Returns:
            json: json response from api.
        """
        if len(params) > 0:
            if 'station_id' in params:
                params['id'] = params['station_id']
                del params['station_id']
            return self.make_get_request(
                "/stations?{query_string}".format(
                    query_string=urlencode(params)),
                end_point=self.DEFAULT_END_POINT)
        return self.make_get_request(
            "/stations", end_point=self.DEFAULT_END_POINT) 
开发者ID:paulokuong,项目名称:noaa,代码行数:26,代码来源:noaa.py

示例10: request_encode_url

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def request_encode_url(self, method, url, fields=None, headers=None,
                           **urlopen_kw):
        """
        Make a request using :meth:`urlopen` with the ``fields`` encoded in
        the url. This is useful for request methods like GET, HEAD, DELETE, etc.
        """
        if headers is None:
            headers = self.headers

        extra_kw = {'headers': headers}
        extra_kw.update(urlopen_kw)

        if fields:
            url += '?' + urlencode(fields)

        return self.urlopen(method, url, **extra_kw) 
开发者ID:MediaBrowser,项目名称:plugin.video.emby,代码行数:18,代码来源:request.py

示例11: report

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def report(self,
               hash=None,
               format=None):
        self.__clear_response()

        request_uri = '/publicapi/get/report'

        query = {}
        query['apikey'] = self.api_key
        if hash is not None:
            query['hash'] = hash
        if format is not None:
            query['format'] = format

        response = self.__api_request(request_uri=request_uri,
                                      body=urlencode(query))
        if not response:
            raise PanWFapiError(self._msg)

        if not self.__set_response(response):
            raise PanWFapiError(self._msg) 
开发者ID:PaloAltoNetworks,项目名称:terraform-templates,代码行数:23,代码来源:wfapi.py

示例12: verdict

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def verdict(self,
                hash=None):
        self.__clear_response()

        request_uri = '/publicapi/get/verdict'

        query = {}
        query['apikey'] = self.api_key
        if hash is not None:
            query['hash'] = hash

        response = self.__api_request(request_uri=request_uri,
                                      body=urlencode(query))
        if not response:
            raise PanWFapiError(self._msg)

        if not self.__set_response(response):
            raise PanWFapiError(self._msg) 
开发者ID:PaloAltoNetworks,项目名称:terraform-templates,代码行数:20,代码来源:wfapi.py

示例13: verdicts_changed

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def verdicts_changed(self,
                         date=None):
        self.__clear_response()

        request_uri = '/publicapi/get/verdicts/changed'

        query = {}
        query['apikey'] = self.api_key
        if date is not None:
            query['date'] = date

        response = self.__api_request(request_uri=request_uri,
                                      body=urlencode(query))
        if not response:
            raise PanWFapiError(self._msg)

        if not self.__set_response(response):
            raise PanWFapiError(self._msg) 
开发者ID:PaloAltoNetworks,项目名称:terraform-templates,代码行数:20,代码来源:wfapi.py

示例14: sample

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def sample(self,
               hash=None):
        self.__clear_response()

        request_uri = '/publicapi/get/sample'

        query = {}
        query['apikey'] = self.api_key
        if hash is not None:
            query['hash'] = hash

        response = self.__api_request(request_uri=request_uri,
                                      body=urlencode(query))
        if not response:
            raise PanWFapiError(self._msg)

        if not self.__set_response(response):
            raise PanWFapiError(self._msg) 
开发者ID:PaloAltoNetworks,项目名称:terraform-templates,代码行数:20,代码来源:wfapi.py

示例15: pcap

# 需要导入模块: from urllib import parse [as 别名]
# 或者: from urllib.parse import urlencode [as 别名]
def pcap(self,
             hash=None,
             platform=None):
        self.__clear_response()

        request_uri = '/publicapi/get/pcap'

        query = {}
        query['apikey'] = self.api_key
        if hash is not None:
            query['hash'] = hash
        if platform is not None:
            query['platform'] = platform

        response = self.__api_request(request_uri=request_uri,
                                      body=urlencode(query))
        if not response:
            raise PanWFapiError(self._msg)

        if not self.__set_response(response):
            raise PanWFapiError(self._msg) 
开发者ID:PaloAltoNetworks,项目名称:terraform-templates,代码行数:23,代码来源:wfapi.py


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