本文整理汇总了Python中common.Common.webrequest方法的典型用法代码示例。如果您正苦于以下问题:Python Common.webrequest方法的具体用法?Python Common.webrequest怎么用?Python Common.webrequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common.Common
的用法示例。
在下文中一共展示了Common.webrequest方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _build_fs
# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import webrequest [as 别名]
def _build_fs(self, link, cursor = None):
self.project.log("transaction", "Calculating total dropbox items...", "info", True)
if cursor:
response = Common.webrequest(link, self.oauth_provider.get_auth_header(), self.oauth_provider.http_intercept, urllib.parse.urlencode({'cursor': cursor}))
else:
response = Common.webrequest(link, self.oauth_provider.get_auth_header(), self.oauth_provider.http_intercept, "")
json_response = json.loads(response)
has_more = json_response['has_more']
cursor = json_response['cursor']
for item in json_response['entries']:
self.files.append(item[1])
if has_more:
self._build_fs(link, cursor)
示例2: _downloader
# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import webrequest [as 别名]
def _downloader(self):
while (not self.empty()) and (not self.project.shutdown_signal):
t = threading.current_thread()
Common.check_for_pause(self.project)
slip = self.get()
if callable(slip.url):
file_url = slip.url()
else:
file_url = slip.url
t.name = "Downloading: " + slip.item[slip.filename_key]
self.project.log("transaction", "Downloading " + slip.item[slip.filename_key], "info", True)
try:
data = Common.webrequest(
file_url, self.headers(), self.http_callback, None, False, True
) # Response object gets passed to shutil.copyfileobj
self.storage_callback(data, slip)
except urllib.error.HTTPError as err:
self.project.log(
"exception",
"{} failed to download - HTTPError {}".format(slip.item[slip.filename_key], err.code),
"warning",
)
if self.project.shutdown_signal:
self.project.log(
"exception",
"{} received shutdown signal. Stopping...".format(threading.current_thread().name),
"warning",
)
else:
self.project.log("transaction", "{} has completed.".format(threading.current_thread().name), "info")
示例3: _get_download_uri
# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import webrequest [as 别名]
def _get_download_uri(self, file):
response = Common.webrequest(self.oauth_provider.config['API_ENDPOINT'] + '/media/auto' + file['path'], self.oauth_provider.get_auth_header(), self.oauth_provider.http_intercept)
json_response = json.loads(response)
if 'url' in json_response:
return json_response['url']
else:
return None
示例4: get_access_token
# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import webrequest [as 别名]
def get_access_token(self, client_id, client_secret):
response_type = 'code'
query_string = {}
if self.provider == "google":
query_string = (
{'redirect_uri': self.config['REDIRECT_URI'], 'response_type': response_type,
'client_id': client_id,
'scope': self.project.config['OAUTH_SCOPE'], 'approval_prompt': 'force', 'access_type': 'offline'})
elif self.provider == "dropbox":
query_string = ({'response_type': response_type, 'client_id': client_id})
params = urllib.parse.urlencode(query_string)
step1 = self.config['OAUTH_ENDPOINT'] + '?' + params
Common.launch_browser(step1)
code = IO.get("Authorization Code:")
query_string = ({'code': code, 'grant_type': 'authorization_code', 'client_id': client_id, 'client_secret': client_secret})
if self.provider == "google":
query_string['scope'] = ''
query_string['redirect_uri'] = self.config['REDIRECT_URI']
params = urllib.parse.urlencode(query_string)
response = Common.webrequest(self.config['TOKEN_ENDPOINT'], {'content-type': 'application/x-www-form-urlencoded;charset=utf-8'}, self.http_intercept, params)
json_response = json.loads(response)
self.parse_token(json_response)
self.project.save("OAUTH", self.oauth)
示例5: _build_fs
# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import webrequest [as 别名]
def _build_fs(self, link):
self.project.log("transaction", "Calculating total drive items...", "info", True)
response = Common.webrequest(link, self.oauth_provider.get_auth_header(), self.oauth_provider.http_intercept)
json_response = json.loads(response)
if 'nextLink' in json_response:
items = json_response['items']
self._add_items_to_files(items)
self._build_fs(json_response['nextLink'])
else:
items = json_response['items']
self._add_items_to_files(items)
示例6: refresh
# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import webrequest [as 别名]
def refresh(self, client_id, client_secret):
if self.provider == "google":
query_string = ({'client_secret': client_secret, 'grant_type': 'refresh_token',
'refresh_token': self.oauth['refresh_token'], 'client_id': client_id})
params = urllib.parse.urlencode(query_string)
response = Common.webrequest(self.config['TOKEN_ENDPOINT'],
{'content-type': 'application/x-www-form-urlencoded;charset=utf-8'},
self.http_intercept, params)
json_response = json.loads(response)
self.parse_token(json_response)
else:
self.project.log("exception", "WARNING - Authorization is being rejected by host API.", "critical", True)
示例7: _build_fs
# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import webrequest [as 别名]
def _build_fs(self, link):
self.project.log("transaction", "Calculating total GMail items...", "info", True)
response = Common.webrequest(link, self.oauth_provider.get_auth_header(), self.oauth_provider.http_intercept)
json_response = json.loads(response)
if 'nextPageToken' in json_response:
threads = json_response['threads']
self._add_items_to_threads(threads)
next_url = Common.joinurl(self.project.config['API_ENDPOINT'], "users/me/threads?userId=me&includeSpamTrash=true&pageToken={}".format(json_response['nextPageToken']))
self._build_fs(next_url)
else:
items = json_response['threads']
self._add_items_to_threads(items)