本文整理匯總了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']
示例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
示例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]
示例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')
示例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
示例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']