简体   繁体   English

python 上的 Telepot,无法使用 sendGroupMedia 发送多张照片

[英]Telepot on python, can't send multiple photos with sendGroupMedia

I'm trying to send 2 or 3 photos at the same time, so they're displayed as one message on my channel.我试图同时发送 2 或 3 张照片,因此它们在我的频道上显示为一条消息。 To send one photos I used python's requests library, with this line of code;为了发送一张照片,我使用了 python 的requests库,以及这行代码;

pic = {'photo' : open('p.jpeg', 'rb')}
print(requests.get(f'https://api.telegram.org/bot{apiKey}/sendPhoto?chat_id={chat_id}?disable_notification=True', files=pic))

Now to send more at once I use telepot .现在要一次发送更多,我使用telepot I'm doing this:我这样做:

bot = telepot.Bot(apiKey)
bot.sendMediaGroup(
    chat_id=chat_id,
    media=[
        {'media' : open( 'p.jpeg', 'rb')},
        {'media' : open('p1.jpeg', 'rb')}
    ],
    disable_notification=True
)

The problem is I don't precise the type of media being transferred.问题是我没有准确说明正在传输的媒体类型。 I tried doing:我试着做:

media = {'media' :      
                    {'photo' : open( 'p.jpeg', 'rb')},
                    {'photo' : open('p1.jpeg', 'rb')}
        }

But media parameter must be an array.但是media参数必须是一个数组。

I also tried to pass a double sized dictionary as argument to requests.get(...) , it didn't work either.我还尝试将双倍大小的字典作为参数传递给requests.get(...) ,它也没有用。

Could you guys help me out?你们能帮帮我吗? Thank you谢谢

Well, problem solved, eventually I had to do this:好吧,问题解决了,最终我不得不这样做:

bot.sendMediaGroup(
    chat_id=chat_id,
    media=[
        {'media' : open( 'p.jpeg', 'rb'), 'type' : 'photo'},
        {'media' : open('p1.jpeg', 'rb'), 'type' : 'photo'}
    ],
    disable_notification=True
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tkinter-无法同时打开多张照片(Python) - Tkinter - can't open multiple photos at the same time (Python) Python请求无法使用相同的密钥发送多个标头 - Python requests can't send multiple headers with same key 如何使用 python 在电报上发送照片 - How to send photos on telegram with python Python:无法将电子邮件发送给多个收件人 - Python: can't get email to send to multiple recipients Python Telepot 机器人内联键盘 - Python Telepot bot inline keybard Google云端硬盘API(python)-无法检索照片 - Google Drive API (python) - Can't retrieve Photos Python idle 不允许使用通过子进程调用在 shell 中安装 Telepot - Python idle doesn't let install telepot in shell using calling through subprocess 使 unicode 成为存储在变量中的字符串,然后用 Telepot 发送它 - make unicode a string stored in a variable and then send it with telepot 为什么我不能使用 Python 中的此代码将照片上传到谷歌照片(使用 Python 中的 REST 的谷歌照片 api)? - Why can't I upload to google photos with this code from python (google photos api using REST from Python)? 无法下载文件,权限错误:[Errno 13] 权限被拒绝:'C:\\\\Users\\\\***\\\\Desktop' with telepot - Can't download files, PermissionError: [Errno 13] Permission denied: 'C:\\Users\\***\\Desktop' with telepot
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM