davidchua / pymessenger

A Python Wrapper for the FB Messenger Bot API (Send/Receive API)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unhashable type: 'dict' with send_attachment

sergey-sc opened this issue · comments

hi.
recieving error unhashable type: 'dict' with send_attachment and send_image functions.


  File "D:\projects\Test\bot.py", line 71, in send_attachment
    'id': recipient_id

TypeError: unhashable type: 'dict'

print(recipient_id, attachment_type,attachment_path):
1336772359690730 image d:\projects\Test\logo.png

send_attachment_url and other functions works fine
Thank you in advance

There are extra brackets inside recipient.

I had that same problem. But even when I fixed it by removing the extra brackets, was the MultipartEncoder that broke...

I had to cast every dict to a string inside the payload to actually get the request to be sent.

My payload looks like this now:

payload = {
    'recipient': str({
        'id': recipient_id
    }),
    'notification_type': str(notification_type),
    'message': str({
        'attachment': {
            'type': attachment_type,
            'payload': {}
        }
    }),
    'filedata': (os.path.basename(attachment_path), open(attachment_path, 'rb'))
}

But still, the Graph API refuses resquest by sending this error message:

{  
   'error':{  
      'fbtrace_id':'Fp69bNu5ULJ',
      'type':'GraphMethodException',
      'message':'Unsupported post request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api',
      'code':100
   }
}

Now I don't know what step to take next... can you guys help me?

I've found the error. The upload file request must call https://graph.facebook.com/v2.6/me/messages?access_token=ACCESS_TOKEN and was calling https://graph.facebook.com/v2.6.

I've created a pull request #31