Do not json-dump files
This commit is contained in:
parent
3e6fc8ba42
commit
7582b4cce4
@ -99,7 +99,10 @@ class TelegramBot(object):
|
|||||||
data = aiohttp.FormData()
|
data = aiohttp.FormData()
|
||||||
for key, value in parameters.items():
|
for key, value in parameters.items():
|
||||||
if not (key in exclude or value is None):
|
if not (key in exclude or value is None):
|
||||||
if type(value) in (int, dict, list,):
|
if (
|
||||||
|
type(value) in (int, list,)
|
||||||
|
or (type(value) is dict and 'file' not in value)
|
||||||
|
):
|
||||||
value = json.dumps(value, separators=(',', ':'))
|
value = json.dumps(value, separators=(',', ':'))
|
||||||
data.add_field(key, value)
|
data.add_field(key, value)
|
||||||
return data
|
return data
|
||||||
@ -206,7 +209,9 @@ class TelegramBot(object):
|
|||||||
certificate = self.certificate
|
certificate = self.certificate
|
||||||
if type(certificate) is str:
|
if type(certificate) is str:
|
||||||
try:
|
try:
|
||||||
certificate = open(certificate, 'r')
|
certificate = dict(
|
||||||
|
file=open(certificate, 'r')
|
||||||
|
)
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
logging.error(f"{e}\nCertificate set to `None`")
|
logging.error(f"{e}\nCertificate set to `None`")
|
||||||
certificate = None
|
certificate = None
|
||||||
@ -214,8 +219,8 @@ class TelegramBot(object):
|
|||||||
'setWebhook',
|
'setWebhook',
|
||||||
parameters=locals()
|
parameters=locals()
|
||||||
)
|
)
|
||||||
if certificate is not None: # Close certificate file, if it was open
|
if type(certificate) is dict: # Close certificate file, if it was open
|
||||||
certificate.close()
|
certificate['file'].close()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def deleteWebhook(self):
|
async def deleteWebhook(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user