【发布时间】:2017-01-07 21:37:35
【问题描述】:
我无法发送照片,这里的代码有错误:
if command.startswith('/rank '):
rank(msg)
def rank(msg):
chat_id = msg['chat']['id']
command = msg['text']
user = msg['text'][6:]
graphUrl = 'https://www.website.com/servlet/graph/' + user + '-in_US.png'
print graphUrl
theGraph = urllib2.urlopen(graphUrl)
bot.sendPhoto(chat_id, theGraph, caption=('rank graph for ' + user + '.'))
错误:2016-12-30T17:17:50.803142+00:00 app[worker.1]: TelegramError: (u'Bad Request:照片的扩展名不受支持。使用 .jpg 之一, .jpeg, # .gif, .png, .tif 或 .bmp', 400, {u'ok': False, u'description':u'Bad Request:照片的扩展名不受支持。利用 .jpg、.jpeg、# .gif、.png、.tif 或 .bmp' 之一,u'error_code': 400})
我的文件是.png,我哪里错了?
如果我将sendPhoto() 替换为sendDocument() 一切正常,但我的项目中需要照片。
如果我直接在 sendPhoto 中输入graphUrl,而不使用 urllib2,它就不起作用(错误 400 - 错误请求)。
【问题讨论】:
标签: python python-2.7 urllib2 telegram telegram-bot