本文整理汇总了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