本文整理匯總了Python中urllib2.quote方法的典型用法代碼示例。如果您正苦於以下問題:Python urllib2.quote方法的具體用法?Python urllib2.quote怎麽用?Python urllib2.quote使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類urllib2
的用法示例。
在下文中一共展示了urllib2.quote方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_proxy_info
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def _get_proxy_info(context):
if not context.get('proxy_hostname') or not context.get('proxy_port'):
return None
user_pass = ''
if context.get('proxy_username') and context.get('proxy_password'):
username = quote(context['proxy_username'], safe='')
password = quote(context['proxy_password'], safe='')
user_pass = '{user}:{password}@'.format(
user=username, password=password)
proxy = 'http://{user_pass}{host}:{port}'.format(
user_pass=user_pass, host=context['proxy_hostname'],
port=context['proxy_port'])
proxies = {
'http': proxy,
'https': proxy,
}
return proxies
示例2: get_distance
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def get_distance(self, userID):
""" Fetches the distance from another user
:param userID User ID of target user.
"""
# Create and send HTTP Get to Happn server
h=headers
h.update({
'Authorization' : 'OAuth="' + self.oauth+'"',
'Content-Type' : 'application/json',
})
#@TODO Trim query to just distance request
query='{"fields":"spotify_tracks,modification_date,my_relations,social_synchronization.fields(facebook.fields(id),instagram.fields(pictures.fields(id),username)),school,age,clickable_profile_link,is_invited,type,gender,is_charmed,picture.fields(id,url,is_default).height(92).mode(0).width(92),last_meet_position,profiles.fields(id,url,is_default).height(1136).mode(1).width(640),has_charmed_me,job,first_name,last_invite_received,distance,availability,about,id,workplace,is_accepted"}'
url = 'https://api.happn.fr/api/users/' + str(userID) + '?' + urllib2.quote(query)
try:
r = requests.get(url, headers=h)
except Exception as e:
raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))
if r.status_code == 200: #200 = 'OK'
self.distance = r.json()['data']['distance']
logging.info('Sybil %d m from target',self.distance)
else:
raise HTTP_MethodError(httpErrors[r.status_code])
示例3: downloadSingleType
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def downloadSingleType(bigCate,smallCate,baseDir):
"""
下載某一分類的詞庫,實際作用是修改全局變量讓多線程可以獲取到正確的下載路徑和存儲目錄
:param bigCate: 一級分類
:param smallCate: 二級分類
:param baseDir: 下載目錄
:return: None
"""
global smallCateURL, downloadDir, queue, logFile
smallCateURL = 'http://dict.qq.pinyin.cn/dict_list?sort1=%s&sort2=%s' %(urllib2.quote(bigCate), urllib2.quote(smallCate)) # url編碼
if baseDir[-1] == '/':
print '路徑 '+baseDir+' 末尾不能有/'
return
downloadDir = baseDir+'/'+bigCate+'/'+smallCate
logFile = baseDir+'/download.log'
if not os.path.exists(downloadDir.decode('utf8')): # 目錄不存在的時候創建目錄
os.makedirs(downloadDir.decode('utf8'))
queue.put(smallCateURL)
示例4: sync_song
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def sync_song(self):
for song_detail in self.source_playlist:
song = song_detail[0]
singer = song_detail[1]
search_word = u"{} {}".format(song, singer)
url_sw = quote(search_word.encode('utf8'))
self.browser.get(qq_search_url.format(url_sw))
self.wait.until(lambda browser: browser.find_element_by_class_name("songlist__list"))
sleep(0.5)
@retry(retry_times=3)
def _add(browser):
browser.execute_script("document.getElementsByClassName('songlist__list')[0].firstElementChild.getElementsByClassName('list_menu__add')[0].click()")
sleep(0.5)
browser.find_element_by_css_selector("a[data-dirid='{}']".format(self.target_playlist_tag)).click()
_print(u"song:{} success".format(song))
try:
_add(self.browser)
except RetryException:
_print(u"song:{}, sync error".format(song))
self.failed_list.append(search_word)
else:
self.success_list.append(search_word)
示例5: getcloudvideourl
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def getcloudvideourl(bturl, title):
'''
resolve video url
'''
dlpre = '{0}/req_get_method_vod'.format(cloudurlpre)
# dl = '{0}/vod_dl_all?userid={1}&gcid={2}&filename={3}&t={4}'.format(
# cloudurlpre, xl.userid, gcid,
# urllib2.quote(title), cachetime)
dl = '{0}?url={1}&platform=0&userid={2}&sessionid={3}&cache={4}'.format(
dlpre, urllib.quote(bturl), xl.userid, xl.sid, cachetime)
rsp = xl.urlopen(dl)
vturls = json.loads(rsp)
typ = {'356608': '1080P', '282880': '720P', '225536': '標清'}
vtyps = [(typ[str(i['spec_id'])], i['vod_url_dt17'])
for i in vturls['resp']['vodinfo_list']
if str(i['spec_id']) in typ]
# vtyps = [(typ[k], v['url'])
# for (k, v) in vturls.iteritems() if 'url' in v]
# vtyps.insert(0, ('源碼', surl))
# selitem = dialog.select('清晰度', [v[0] for v in vtyps])
# if selitem is -1: return
# vtyp = vtyps[selitem]
return vtyps
示例6: track_download_request
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def track_download_request(download_url, download_title):
"""Track a download in Piwik"""
from indico_piwik.plugin import PiwikPlugin
if not download_url:
raise ValueError("download_url can't be empty")
if not download_title:
raise ValueError("download_title can't be empty")
request = PiwikRequest(server_url=PiwikPlugin.settings.get('server_api_url'),
site_id=PiwikPlugin.settings.get('site_id_events'),
api_token=PiwikPlugin.settings.get('server_token'),
query_script=PiwikPlugin.track_script)
action_url = quote(download_url)
dt = datetime.now()
request.call(idsite=request.site_id,
rec=1,
action_name=quote(download_title.encode('utf-8')),
url=action_url,
download=action_url,
h=dt.hour, m=dt.minute, s=dt.second)
示例7: search_track
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def search_track(keyword):
'''
return matched qq music songs
'''
keyword = urllib2.quote(keyword.encode("utf8"))
url = 'http://i.y.qq.com/s.music/fcgi-bin/search_for_qq_cp?' + \
'g_tk=938407465&uin=0&format=jsonp&inCharset=utf-8' + \
'&outCharset=utf-8¬ice=0&platform=h5&needNewCode=1' + \
'&w=%s&zhidaqu=1&catZhida=1' + \
'&t=0&flag=1&ie=utf-8&sem=1&aggr=0&perpage=20&n=20&p=1' + \
'&remoteplace=txt.mqq.all&_=1459991037831&jsonpCallback=jsonp4'
response = _qq_h(url % keyword)
data = json.loads(response[len('jsonp4('):-len(')')])
result = []
for song in data["data"]["song"]["list"]:
result.append(_convert_song(song))
return result
示例8: emit
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def emit(self, record):
try:
msg = record.getMessage()
log_data = "PLAINTEXT=" + urllib2.quote(simplejson.dumps(
{
'msg':msg,
'localip':self.localip,
'publicip':self.publicip,
'tenant':'TODO :)'
}
))
urllib2.urlopen(self.base_url, log_data)
except(KeyboardInterrupt, SystemExit):
raise
except:
self.handleError(record)
示例9: find
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def find(self, query):
"""return the first 100 compounds that match the query"""
this = "Search.asmx/SimpleSearch?query=%s&token=%s" % (quote(query), self._token)
res = self.http_get(this, frmt="xml")
res = self.easyXML(res)
Ids = [int(x.text) for x in res.findAll("int")]
return Ids
示例10: get_json_result
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def get_json_result(self, query_items, arguments=None):
path = '/json/' + '/'.join(urllib2.quote(item)
for item in query_items)
if arguments is not None:
path += '?' + urllib2.urlencode(arguments)
url = self.master_url + path
try:
request = urllib2.urlopen(url)
except urllib2.HTTPError, err:
# Turn 404 into a result missing error.
if err.code == 404:
raise ResultMissing
# Log this failure.
os = StringIO.StringIO()
print >>os, "*** ERROR: failure in 'get_json_result(%r, %r)' ***" %(
query_items, arguments)
print >>os, "URL: %r" % url
print >>os, "\n-- Traceback --"
traceback.print_exc(file = os)
if self.logger:
self.logger.warning(os.getvalue())
else:
print >>sys.stderr, os.getvalue()
raise UnknownFailure
示例11: get_conversations
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def get_conversations(self, offset=0,limit=64):
""" Get conversations with userID from Happn server
:param userID User ID of target user.
:param offset Offset of conversations to recieve
:param limit Number of conversations to recieve
"""
# Create and send HTTP Get to Happn server
h={ #For some reason header update doesnt work
'http.useragent' : 'Happn/1.0 AndroidSDK/0',
'Authorization' : 'OAuth="' + self.oauth+'"',
'Content-Type' : 'application/json',
'User-Agent' : 'Happn/19.1.0 AndroidSDK/19',
'Host' : 'api.happn.fr',
'Connection' : 'Keep-Alive',
'Accept-Encoding': 'gzip, deflate'
}
query ='fields=creation%5Fdate%2Cparticipants%2Efields%28user%2Efields%28picture%2Efields%28id%2Curl%2Cis%5Fdefault%29%2Eheight%28120%29%2Emode%280%29%2Ewidth%28120%29%2Cage%2Cclickable%5Fmessage%5Flink%2Cid%2Cfirst%5Fname%2Cis%5Fmoderator%29%29%2Cmodification%5Fdate%2Cid%2Cmessages%2Efields%28sender%2Efields%28id%2Cfirst%5Fname%29%2Ccreation%5Fdate%2Cmessage%2Cid%29%2Eoffset%280%29%2Elimit%283%29%2Cis%5Fread&offset=' + str(offset) + '&limit=' + str(limit)
#'{"fields":"creation_date,participants.fields(user.fields(picture.fields(id,url,is_default).height(120).mode(0).width(120),age,clickable_message_link,id,first_name,is_moderator)),modification_date,id,messages.fields(sender.fields(id,first_name),creation_date,message,id).offset(0).limit(3),is_read", "offset": '+str(offset)+'}'
url = 'https://api.happn.fr/api/users/' + str(self.id) + '/conversations?' + urllib2.quote(query)
logging.debug("Using url = {}".format(url))
logging.debug("SenderID: {}".format(self.id))
try:
r = requests.get(url, headers=h)
except Exception as e:
raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))
if r.status_code == 200: #200 = 'OK'
logging.debug("Return code: {}".format(r.status_code))
return json.loads(json.dumps(r.json()['data'], sort_keys=True, indent=4, separators=(',', ': ')))
else:
logging.warn("Error: {}".format(r.status_code))
raise HTTP_MethodError(httpErrors[r.status_code])
示例12: get_messages
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def get_messages(self, conversationID, offset=0,limit=64):
""" Get conversations with userID from Happn server
:param conversationID ID of conversation between user1 and user2.
:param offset Offset of messages to recieve
:param limit Number of messages to recieve
"""
# Create and send HTTP Get to Happn server
h={ #For some reason header update doesnt work
'http.useragent' : 'Happn/1.0 AndroidSDK/0',
'Authorization' : 'OAuth="' + self.oauth+'"',
'Content-Type' : 'application/json',
'User-Agent' : 'Happn/19.1.0 AndroidSDK/19',
'Host' : 'api.happn.fr',
'Connection' : 'Keep-Alive',
'Accept-Encoding': 'gzip, deflate'
}
query = '{fields":"sender.fields(picture.fields(id,url,is_default).height(70).mode(0).width(70),clickable_message_link,id,first_name,is_moderator),creation_date,message,id"}'
#fields=sender%2Efields%28picture%2Efields%28id%2Curl%2Cis%5Fdefault%29%2Eheight%2870%29%2Emode%280%29%2Ewidth%2870%29%2Cclickable%5Fmessage%5Flink%2Cid%2Cfirst%5Fname%2Cis%5Fmoderator%29%2Ccreation%5Fdate%2Cmessage%2Cid&offset=0&limit=27
url = 'https://api.happn.fr/api/conversations/' + str(conversationID) + '/messages?' + urllib2.quote(query) + "%offset="+str(offset)+"&limit="+str(limit)
#
logging.debug("Using url = {}".format(url))
logging.debug("convoID: {}".format(conversationID))
try:
r = requests.get(url, headers=h)
except Exception as e:
raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))
if r.status_code == 200: #200 = 'OK'
logging.debug("Return code: {}".format(r.status_code))
return json.loads(json.dumps(r.json()['data'], sort_keys=True, indent=4, separators=(',', ': ')))
else:
logging.warn("Error: {}".format(r.status_code))
raise HTTP_MethodError(httpErrors[r.status_code])
示例13: get_recommendations
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def get_recommendations(self, limit=16, offset=0):
""" Get recs from Happn server
:param limit Number of reccomendations to recieve
:param offset Offset index for reccomendation list
"""
# Create and send HTTP Get to Happn server
h={ #For some reason header update doesnt work
'http.useragent' : 'Happn/1.0 AndroidSDK/0',
'Authorization' : 'OAuth="' + self.oauth+'"',
'Content-Type' : 'application/json',
'User-Agent' : 'Happn/19.1.0 AndroidSDK/19',
'Host' : 'api.happn.fr',
'Connection' : 'Keep-Alive',
'Accept-Encoding': 'gzip'
}
query = '{"types":"468","limit":'+str(limit)+',"offset":'+str(offset)+',"fields":"id,modification_date,notification_type,nb_times,notifier.fields(id,job,is_accepted,workplace,my_relation,distance,gender,my_conversation,is_charmed,nb_photos,first_name,age,profiles.mode(1).width(360).height(640).fields(width,height,mode,url))"}'
url = 'https://api.happn.fr/api/users/' + self.id +'/notifications/?query=' + urllib2.quote(query)
try:
r = requests.get(url, headers=h)
except Exception as e:
raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))
if r.status_code == 200: #200 = 'OK'
return json.loads(json.dumps(r.json()['data'], sort_keys=True, indent=4, separators=(',', ': ')))
else:
raise HTTP_MethodError(httpErrors[r.status_code])
示例14: get_declined
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def get_declined(self, limit=128, offset=0):
""" Get declined people from Happn server
:param limit Number of people to recieve
:param offset Offset index for reccomendation list
"""
# Create and send HTTP Get to Happn server
h={ #For some reason header update doesnt work
'http.useragent' : 'Happn/1.0 AndroidSDK/0',
'Authorization' : 'OAuth="' + self.oauth+'"',
'Content-Type' : 'application/json',
'User-Agent' : 'Happn/19.1.0 AndroidSDK/19',
'Host' : 'api.happn.fr',
'Connection' : 'Keep-Alive',
'Accept-Encoding': 'gzip'
}
query = '{"types":"468","limit":'+str(limit)+',"offset":'+str(offset)+',"fields":"is_charmed,modification_date,age,id,my_relation,distance,first_name"}'
url = 'https://api.happn.fr/api/users/me/rejected?' + urllib2.quote(query)
try:
r = requests.get(url, headers=h)
except Exception as e:
raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))
if r.status_code == 200: #200 = 'OK'
return json.loads(json.dumps(r.json()['data'], sort_keys=True, indent=4, separators=(',', ': ')))
else:
raise HTTP_MethodError(httpErrors[r.status_code])
示例15: _pam_auth
# 需要導入模塊: import urllib2 [as 別名]
# 或者: from urllib2 import quote [as 別名]
def _pam_auth(self, query, apicode=0, callback=None, error=None):
if 'timestamp' not in query:
query['timestamp'] = int(time.time())
## Global Grant?
if 'auth' in query and not query['auth']:
del query['auth']
if 'channel' in query and not query['channel']:
del query['channel']
if 'channel-group' in query and not query['channel-group']:
del query['channel-group']
params = "&".join([
x + "=" + quote(
str(query[x]), safe=""
) for x in sorted(query)
])
sign_input = "{subkey}\n{pubkey}\n{apitype}\n{params}".format(
subkey=self.subscribe_key,
pubkey=self.publish_key,
apitype="audit" if (apicode) else "grant",
params=params
)
query['signature'] = self._pam_sign(sign_input)
return self._request({"urlcomponents": [
'v1', 'auth', "audit" if (apicode) else "grant",
'sub-key',
self.subscribe_key
], 'urlparams': query},
self._return_wrapped_callback(callback),
self._return_wrapped_callback(error))