के साथ यूआरएल से फोटो भेजना मैंने एक टेलीग्राम बॉट बनाया जो pyTelegramBotAPI wrapper का उपयोग कर यूआरएल से अनुरोध पर फोटो भेजता है। तो मैंने एक डमी फोटो यूआरएल डालने की कोशिश की और परीक्षण किया कि क्या बॉट छवि भेज सकता है लेकिन यह निम्न त्रुटि से विफल रहा है।टेलीग्राम बॉट
telebot.apihelper.ApiException: sendPhoto failed. Returned result: <Response [400]>
मुझे यकीन है कि क्या त्रुटि है नहीं कर रहा हूँ, लेकिन मैं कैसे टेलीग्राम बॉट एपीआई सही ढंग से उपयोग URL से एक तस्वीर भेज सकते हैं? यहां मेरा कोड
import telebot
import time
import urllib
from io import BytesIO
from PIL import Image
TOKEN = '<token here>'
url='http://scontent-b.cdninstagram.com/hphotos-xfa1/t51.2885-15/e15/10919672_584633251672188_179950734_n.jpg'
def listener(*messages):
for m in messages:
chatid = m.chat.id
if m.content_type == 'text':
text = m.text
name = m.fromUser.first_name
msgid = m.message_id
if(text.startswith('/photo')):
img = BytesIO(urllib.request.urlopen(url).read())
tb.send_chat_action(chatid, 'upload_photo')
tb.send_photo(chatid, img, reply_to_message_id=msgid)
tb = telebot.TeleBot(TOKEN)
tb.get_update() # cache exist message
tb.set_update_listener(listener) #register listener
tb.polling()
while True:
time.sleep(1)
मुझे यकीन नहीं है कि मुझे कुछ याद आया है या नहीं।
तो हम सब के बाद टेलीग्राम को अपलोड करने से पहले स्थानीय फ़ोल्डर में पूरी फ़ाइल डाउनलोड करना होगा। डाउनलोड करते समय छवि आकार को कम करने का कोई तरीका है, क्या मैंने स्क्रिप्ट को पूरी तरह से अपनी मशीन पर चलाया है? – Zerocchi
मुझे नहीं पता कि यह वास्तव में क्या है जो आप बनाने की कोशिश कर रहे हैं, लेकिन मुझे यकीन है कि पाइथन के साथ छवियों को संपीड़ित करने के तरीके हैं, केवल _while_ डाउनलोड नहीं। और जब आपको फ़ाइल की आवश्यकता नहीं होती है तो अपने कंप्यूटर से छवि को हटाना सुनिश्चित करें। – Pete
मेरा कोड यहां - मुझे विश्वास है क्योंकि मैं पाइथन के लिए नया हूं - छवि को स्थानीय फ़ोल्डर में डाउनलोड करने की आवश्यकता नहीं है: http://stackoverflow.com/a/32441772/1097372 – Iyas