fbchat-dev / fbchat

Facebook Chat (Messenger) for Python
https://fbchat.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.19k stars 412 forks source link

Sending images to chat from local #199

Closed Hydrochoeris closed 7 years ago

Hydrochoeris commented 7 years ago

Dear Carpedm20,

I cannot get self.sendLocalImage() to work, can you tell me how to do this? I get this ErrorCode:

Traceback (most recent call last):
  File "C:\Users\Gebruiker\Desktop\python\Python 2.7.13\lib\site-packages\fbchat\client.py", line 1366, in _parseMessage
    thread_id=thread_id, thread_type=thread_type, ts=ts, metadata=metadata, msg=m)
  File "C:\Users\Gebruiker\Desktop\python\Works\FbChat_get_all_fotos\FbChat_get_all_fotos\ClientListen.py", line 123, in onMessage
    self.sendLocalImage(image_path ='C:\Users\Gebruiker\Desktop\python\Works\FbChat_get_all_fotos\FbChat_get_all_fotos\delet\delet_this.jpg' , message='', thread_id=thread_id, thread_type=thread_type)
  File "C:\Users\Gebruiker\Desktop\python\Python 2.7.13\lib\site-packages\fbchat\client.py", line 964, in sendLocalImage
    image_id = self._uploadImage(image_path, open(image_path, 'rb'), mimetype)
  File "C:\Users\Gebruiker\Desktop\python\Python 2.7.13\lib\site-packages\fbchat\client.py", line 905, in _uploadImage
    return j['payload']['metadata'][0]['image_id']
IndexError: list index out of range

for using this line of code:

self.sendLocalImage(image_path ='C:\Users\Gebruiker\Desktop\python\Works\FbChat_get_all_fotos\FbChat_get_all_fotos\delet\delet_this.jpg' , message='', thread_id=thread_id, thread_type=thread_type)

Am I missing something?

sdnian commented 7 years ago

Maybe you can try.. this line:

image_path ='C:\Users\Gebruiker\Desktop\python\Works\FbChat_get_all_fotos\FbChat_get_all_fotos\delet\delet_this.jpg'

change to:

image_path ='C:/Users/Gebruiker/Desktop/python/Works/FbChat_get_all_fotos/FbChat_get_all_fotos/delet/delet_this.jpg'

Hydrochoeris commented 7 years ago

Thank you sdnian.

It works perfectly. And I feel stupid I didn't even try that.