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


Python urlparse.urlencode方法代码示例

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


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

示例1: _GetAccessToken

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlencode [as 别名]
def _GetAccessToken(self):
    """Gets oauth2 access token for Gitkit API using service account.

    Returns:
      string, oauth2 access token.
    """
    d = {
        'assertion': self._GenerateAssertion(),
        'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
    }
    try:
        body = parse.urlencode(d)
    except AttributeError:
        body = urllib.urlencode(d)
    req = urllib_request.Request(RpcHelper.TOKEN_ENDPOINT)
    req.add_header('Content-type', 'application/x-www-form-urlencoded')
    binary_body = body.encode('utf-8')
    raw_response = urllib_request.urlopen(req, binary_body)
    return simplejson.loads(raw_response.read())['access_token'] 
开发者ID:google,项目名称:identity-toolkit-python-client,代码行数:21,代码来源:rpchelper.py

示例2: getCsvReport

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlencode [as 别名]
def getCsvReport(product_list, startdate, enddate, source_obj):
        print
        print ("Requesting a csv report for the given time period")
        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8','Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'}
        path = "/billing-usage/v1/contractUsageData/csv"

        parameters = {  "reportSources" :[source_obj],
			"products"	:product_list,
                        "startDate"     :startdate,
                        "endDate"       :enddate
                }
        print
        data_string = parse.urlencode({p: json.dumps(parameters[p]) for p in parameters})
        products_result = session.post(parse.urljoin(baseurl,path),data=data_string, headers=headers)
        products_csv = products_result.text
        return products_csv 
开发者ID:akamai,项目名称:api-kickstart,代码行数:18,代码来源:billing_usage.py

示例3: create_api_key

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlencode [as 别名]
def create_api_key():
        """ Interactively create a new API key via Zotero's OAuth API.

        Requires the user to enter a verification key displayed in the browser.

        :returns:   API key and the user's library ID
        """
        auth = OAuth1Service(
            name='zotero',
            consumer_key=CLIENT_KEY,
            consumer_secret=CLIENT_SECRET,
            request_token_url=REQUEST_TOKEN_URL,
            access_token_url=ACCESS_TOKEN_URL,
            authorize_url=AUTH_URL,
            base_url=BASE_URL)
        token, secret = auth.get_request_token(
            params={'oauth_callback': 'oob'})
        auth_url = auth.get_authorize_url(token)
        auth_url += '&' + urlencode({
            'name': 'zotero-cli',
            'library_access': 1,
            'notes_access': 1,
            'write_access': 1,
            'all_groups': 'read'})
        click.echo("Opening {} in browser, please confirm.".format(auth_url))
        click.launch(auth_url)
        verification = click.prompt("Enter verification code")
        token_resp = auth.get_raw_access_token(
            token, secret, method='POST',
            data={'oauth_verifier': verification})
        if not token_resp:
            logging.debug(token_resp.content)
            click.fail("Error during API key generation.")
        access = urlparse.parse_qs(token_resp.text)
        return access['oauth_token'][0], access['userID'][0] 
开发者ID:jbaiter,项目名称:zotero-cli,代码行数:37,代码来源:backend.py

示例4: _BuildOobLink

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlencode [as 别名]
def _BuildOobLink(self, param, mode):
    """Builds out-of-band URL.

    Gitkit API GetOobCode() is called and the returning code is combined
    with Gitkit widget URL to building the out-of-band url.

    Args:
      param: dict of request.
      mode: string, Gitkit widget mode to handle the oob action after user
          clicks the oob url in the email.

    Raises:
      GitkitClientError: if oob code is not returned.

    Returns:
      A string of oob url.
    """
    code = self.rpc_helper.GetOobCode(param)
    if code:
      parsed = list(parse.urlparse(self.widget_url))

      query = dict(parse.parse_qsl(parsed[4]))
      query.update({'mode': mode, 'oobCode': code})

      try:
        parsed[4] = parse.urlencode(query)
      except AttributeError:
        parsed[4] = urllib.urlencode(query)

      return code, parse.urlunparse(parsed)
    raise errors.GitkitClientError('invalid request') 
开发者ID:google,项目名称:identity-toolkit-python-client,代码行数:33,代码来源:gitkitclient.py

示例5: __init__

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlencode [as 别名]
def __init__(self, options):
        self._parse_options(options)
        self._configure_session()
        # urllib has different interface for py27 and py34
        try:
            self._urlencode = urllib.urlencode
            self._quote = urllib.quote
            self._urljoin = urlparse.urljoin
        except AttributeError:
            self._urlencode = urlparse.urlencode
            self._quote = urlparse.quote
            self._urljoin = urlparse.urljoin 
开发者ID:infobloxopen,项目名称:infoblox-client,代码行数:14,代码来源:connector.py

示例6: getProducts

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import urlencode [as 别名]
def getProducts(parameter_obj,startdate,enddate):
	print
	print ("Requesting a list of products for the given time period")
	headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8','Accept':'application/json'}
	path = "/billing-usage/v1/products"

	parameters = {	"reportSources"	:parameter_obj,
			"startDate"	:startdate,
			"endDate"	:enddate
		}
  
	data_string = encoder.urlencode({p: json.dumps(parameters[p]) for p in parameters})
	products_result = session.post(parse.urljoin(baseurl,path),data=data_string, headers=headers)
	products_obj = json.loads(products_result.text)
	return products_obj['contents'] 
开发者ID:akamai,项目名称:api-kickstart,代码行数:17,代码来源:billing_usage.py


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