2017-05-11 5 views
1

이미지 파이썬 전보의 API하지만 나는 예외가 발생 해요 :다운로드 내가 이미지를 다운로드에 대한 자신의 간단한 튜토리얼을 따라

telegram.photosize.PhotoSize object at ... is not JSON serializable 

이미지를 잡기위한 기능은 다음과 같습니다 :

def photo(bot, update): 
    file_id = update.message.photo[-1] 
    newFile = bot.getFile(file_id) 
    newFile.download('test.jpg') 
    bot.sendMessage(chat_id=update.message.chat_id, text="download succesfull") 

photo_handler = MessageHandler(Filters.photo, photo) 
dispatcher.add_handler(photo_handler) 

에서 이 시점에서 내가 뭘 잘못하고 인터넷에 대한 해결책을 찾을 수 없는지 전혀 모른다.

답변

2

나는 데이터 모양을 오해하고있다. 원래 update.message.photo 컬렉션에는 파일 ID 만있는 것으로 생각했습니다. 이로 인해 ID로 파일을 가져올 때 잘못된 종류의 객체를 전달하게되었습니다. 파일 ID를 꺼내하기 위해, 내가 마지막 사진 떨어져 file_id을 얻을 필요 [? 난 내 자신의 질문에 대답 할 수]

file_id = update.message.photo[-1].file_id 
+0

가에서 참조하시기 바랍니다 (http://stackoverflow.com/help/self-answer) 이틀 후에 돌아와 답을 확인하십시오. 그러나 다른 사용자를 위해 몇 가지 정보를 추가하십시오. –