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