本文整理匯總了Python中addon.common.net.Net.set_cookies方法的典型用法代碼示例。如果您正苦於以下問題:Python Net.set_cookies方法的具體用法?Python Net.set_cookies怎麽用?Python Net.set_cookies使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類addon.common.net.Net
的用法示例。
在下文中一共展示了Net.set_cookies方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __http_get_with_retry_1
# 需要導入模塊: from addon.common.net import Net [as 別名]
# 或者: from addon.common.net.Net import set_cookies [as 別名]
def __http_get_with_retry_1(self, url, headers):
utils.log('Fetching URL: %s' % url, xbmc.LOGDEBUG)
net = Net()
cookiejar = _1CH.get_profile()
cookiejar = os.path.join(cookiejar, 'cookies')
net.set_cookies(cookiejar)
retries=0
html=None
while retries<=MAX_RETRIES:
try:
html = net.http_GET(url, headers=headers).content
# if no exception, jump out of the loop
break
except socket.timeout:
retries += 1
utils.log('Retry #%s for URL %s because of timeout' % (retries, url), xbmc.LOGWARNING)
continue
except urllib2.HTTPError as e:
# if it's a temporary code, retry
if e.code in TEMP_ERRORS:
retries += 1
utils.log('Retry #%s for URL %s because of HTTP Error %s' % (retries, url, e.code), xbmc.LOGWARNING)
continue
# if it's not pass it back up the stack
else:
raise
else:
raise
return html
示例2: request
# 需要導入模塊: from addon.common.net import Net [as 別名]
# 或者: from addon.common.net.Net import set_cookies [as 別名]
def request(self, uri, params=None, query=None, headers=None, return_soup=False, return_json=False):
COOKIE_JAR = vfs.join(COOKIE_PATH, self.service + ".lwp")
net = Net()
net.set_cookies(COOKIE_JAR)
if headers:
headers["Referer"] = self.referrer
headers["Accept"] = self.ACCEPT
headers["User-Agent"] = self.USER_AGENT
else:
headers = {"Referer": self.referrer, "Accept": self.ACCEPT, "User-Agent": self.USER_AGENT}
if query:
uri = uri % urllib.urlencode(query)
if params:
html = net.http_POST(self.base_url + uri, params, headers=headers).content
else:
html = net.http_GET(self.base_url + uri, headers=headers).content
net.save_cookies(COOKIE_JAR)
if return_soup:
return BeautifulSoup(html)
elif return_json:
return json.loads(html)
else:
return html