Use requests.Session.
This commit is contained in:
parent
97d1467210
commit
d10af70992
1 changed files with 13 additions and 9 deletions
|
@ -37,6 +37,7 @@ class Mega:
|
||||||
self.request_id = crypto.make_id(10)
|
self.request_id = crypto.make_id(10)
|
||||||
self._trash_folder_node_id = None
|
self._trash_folder_node_id = None
|
||||||
self.shared_keys = {}
|
self.shared_keys = {}
|
||||||
|
self.requests_session = requests.Session()
|
||||||
|
|
||||||
if options is None:
|
if options is None:
|
||||||
options = {}
|
options = {}
|
||||||
|
@ -60,7 +61,7 @@ class Mega:
|
||||||
data = [data]
|
data = [data]
|
||||||
|
|
||||||
url = f'{self.schema}://g.api.{self.domain}/cs'
|
url = f'{self.schema}://g.api.{self.domain}/cs'
|
||||||
req = requests.post(
|
req = self.requests_session.post(
|
||||||
url,
|
url,
|
||||||
params=req_params,
|
params=req_params,
|
||||||
data=json.dumps(data),
|
data=json.dumps(data),
|
||||||
|
@ -750,7 +751,7 @@ class Mega:
|
||||||
else:
|
else:
|
||||||
file_name = attribs['n']
|
file_name = attribs['n']
|
||||||
|
|
||||||
input_file = requests.get(file_url, stream=True).raw
|
input_file = self.requests_session.get(file_url, stream=True).raw
|
||||||
|
|
||||||
if dest_path is None:
|
if dest_path is None:
|
||||||
dest_path = ''
|
dest_path = ''
|
||||||
|
@ -853,17 +854,20 @@ class Mega:
|
||||||
|
|
||||||
# encrypt file and upload
|
# encrypt file and upload
|
||||||
chunk = aes.encrypt(chunk)
|
chunk = aes.encrypt(chunk)
|
||||||
output_file = requests.post(ul_url + "/" +
|
output_file = self.requests_session.post(
|
||||||
str(chunk_start),
|
ul_url + "/" + str(chunk_start),
|
||||||
data=chunk,
|
data=chunk,
|
||||||
timeout=self.timeout)
|
timeout=self.timeout
|
||||||
|
)
|
||||||
completion_file_handle = output_file.text
|
completion_file_handle = output_file.text
|
||||||
logger.info('%s of %s uploaded', upload_progress,
|
logger.info('%s of %s uploaded', upload_progress,
|
||||||
file_size)
|
file_size)
|
||||||
else:
|
else:
|
||||||
output_file = requests.post(ul_url + "/0",
|
output_file = self.requests_session.post(
|
||||||
data='',
|
ul_url + "/0",
|
||||||
timeout=self.timeout)
|
data='',
|
||||||
|
timeout=self.timeout
|
||||||
|
)
|
||||||
completion_file_handle = output_file.text
|
completion_file_handle = output_file.text
|
||||||
|
|
||||||
logger.info('Chunks uploaded')
|
logger.info('Chunks uploaded')
|
||||||
|
|
Loading…
Reference in a new issue