Skip to content

Commit

Permalink
Merge pull request #3 from randhana/2-incorrect-parameter-encoding-in…
Browse files Browse the repository at this point in the history
…-send_image-and-send_document-methods-causing-telegram-api-request-failures

Fix incorrect parameter encoding in send_image and send_document methods
  • Loading branch information
randhana authored Jun 26, 2024
2 parents 6cc28e3 + 9ce7787 commit 1cbf6f9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions telebotpy/telebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def send_image(self, image_filename, caption):
url = f"https://api.telegram.org/bot{self.token}/sendPhoto"
date_time = self._get_date_time()
files = {
'photo': (image_filename, image_file)
'photo': image_file
}
params = {
data = {
'chat_id': self.chat_id,
'caption': caption + " \n" + date_time
}

try:
response = requests.post(url, data=params, files=files)
response = requests.post(url, files=files, data=data)
self._handle_response(response)
except requests.exceptions.RequestException as e:
print(f"Failed to send image: {e}")
Expand All @@ -57,15 +57,15 @@ def send_document(self, document_path, caption):
url = f"https://api.telegram.org/bot{self.token}/sendDocument"
date_time = self._get_date_time()
files = {
'document': (document_path, document_file)
'document': document_file
}
params = {
data = {
'chat_id': self.chat_id,
'caption': caption + " \n" + date_time
}

try:
response = requests.post(url, data=params, files=files)
response = requests.post(url, files=files, data=data)
self._handle_response(response)
except requests.exceptions.RequestException as e:
print(f"Failed to send document: {e}")

0 comments on commit 1cbf6f9

Please sign in to comment.