Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subattachment with no target breaks fetchThreadMessages #412

Closed
femtozer opened this issue Apr 2, 2019 · 2 comments
Closed

Subattachment with no target breaks fetchThreadMessages #412

femtozer opened this issue Apr 2, 2019 · 2 comments
Labels

Comments

@femtozer
Copy link

femtozer commented Apr 2, 2019

Description of the problem

fetchThreadMessages fails when a 'Story' attachment has subattachment without target

Code to reproduce

from fbchat import Client
client = Client("<email>", "<password>")
messages = client.fetchThreadMessages(thread_id='<thread id>')

Attachment causing issue (the second subattachment has no target):

u 'story_attachment': {
  u 'description': {
    u 'text': u 'All in'
  },
  u 'url': u 'https://www.facebook.com/HummusMem3s/videos/1761836197455898/',
  u 'media': {
    u 'playable_url': u 'https://scontent.fcdg2-1.fna.fbcdn.net/v/t42.1790-4/22681982_542126569512864_844556450620506112_n.mp4?_nc_cat=105&efg=eyJ2ZW5jb2RlX3RhZyI6InN2ZV9zZCJ9&_nc_ht=scontent.fcdg2-1.fna&oh=56fd347c2eee5f2478882c875bc46c4d&oe=5CA2BE05',
    u 'image': {
      u 'width': 960,
      u 'uri': u 'https://scontent.fcdg2-1.fna.fbcdn.net/v/t15.5256-10/p960x960/22733241_1761836414122543_5335058377653354496_n.jpg?_nc_cat=109&_nc_ht=scontent.fcdg2-1.fna&oh=1690bbc67939066326509dd661ba42a9&oe=5D0A4E4B',
      u 'height': 960
    },
    u 'animated_image': None,
    u 'is_playable': True,
    u 'playable_duration_in_ms': 2175
  },
  u 'deduplication_key': u '074b788fecf89b21244db0484e93a46a',
  u 'title_with_entities': {
    u 'text': u ''
  },
  u 'source': {
    u 'text': u 'Hummus Memes'
  },
  u 'subattachments': [{
    u 'description': None,
    u 'url': u 'https://www.facebook.com/HummusMem3s/videos/1761836197455898/',
    u 'media': {
      u 'playable_url': u 'https://scontent.fcdg2-1.fna.fbcdn.net/v/t42.1790-4/22681982_542126569512864_844556450620506112_n.mp4?_nc_cat=105&efg=eyJ2ZW5jb2RlX3RhZyI6InN2ZV9zZCJ9&_nc_ht=scontent.fcdg2-1.fna&oh=56fd347c2eee5f2478882c875bc46c4d&oe=5CA2BE05',
      u 'image': {
        u 'width': 960,
        u 'uri': u 'https://scontent.fcdg2-1.fna.fbcdn.net/v/t15.5256-10/p960x960/22733241_1761836414122543_5335058377653354496_n.jpg?_nc_cat=109&_nc_ht=scontent.fcdg2-1.fna&oh=1690bbc67939066326509dd661ba42a9&oe=5D0A4E4B',
        u 'height': 960
      },
      u 'animated_image': None,
      u 'is_playable': True,
      u 'playable_duration_in_ms': 2175
    },
    u 'deduplication_key': u 'ece7d800b1531f9837bfdb5af7659ed3',
    u 'title_with_entities': {
      u 'text': u ''
    },
    u 'source': None,
    u 'style_list': [u 'video_direct_response_autoplay', u 'video_direct_response', u 'video_autoplay', u 'video_inline', u 'video', u 'games_app', u 'fallback'],
    u 'target': {
      u 'video_id': u '1761836197455898',
      u '__typename': u 'Video'
    },
    u 'action_links': [{
      u 'url': u 'https://l.facebook.com/l.php?u=https%3A%2F%2Fbit.ly%2FHummusMemesShop&h=AT1F29zTYt37ZNvcrGZLeOl_q8kfgrls7_9Zv60rL8ZDbvp0HOOK23wOhoHWmot7gJzcMAhjIEOptZQcg5zR9ZylcOFenLV_FBauN0YSmNavmzqwfPgN8EAA2XFcnZO1&s=1',
      u 'title': u 'Acheter'
    }],
    u 'properties': [{
      u 'value': {
        u 'text': u 'all_page_organic_allowed'
      },
      u 'key': u 'can_autoplay_result'
    }],
    u 'messaging_attribution': None
  }, {
    u 'description': None,
    u 'url': None,
    u 'media': None,
    u 'deduplication_key': u '9da1f72eaf1fb33f5cf977690bcb3e95',
    u 'title_with_entities': {
      u 'text': u 'Produits affich\xe9s\xa0:'
    },
    u 'source': None,
    u 'style_list': [u 'commerce_product_mini_list'],
    u 'target': None,
    u 'action_links': [],
    u 'properties': [],
    u 'messaging_attribution': None
  }],
  u 'style_list': [u 'attached_story', u 'fallback'],
  u 'target': {
    u '__typename': u 'Story'
  },
  u 'action_links': [],
  u 'properties': [],
  u 'messaging_attribution': None
}

Traceback

Traceback (most recent call last):
...
File "/.../stats/scanner.py", line 49, in fullscan
  messages = client.fetchThreadMessages(thread_id=thread_id, before=before)
File "/.../env/lib/python2.7/site-packages/fbchat/client.py", line 1105, in fetchThreadMessages
  for message in j["message_thread"]["messages"]["nodes"]
File "/.../env/lib/python2.7/site-packages/fbchat/graphql.py", line 399, in graphql_to_message
  attachment = graphql_to_extensible_attachment(message["extensible_attachment"])
File "/.../env/lib/python2.7/site-packages/fbchat/graphql.py", line 205, in graphql_to_extensible_attachment
  for attachment in story.get("subattachments")
File "/.../env/lib/python2.7/site-packages/fbchat/graphql.py", line 225, in graphql_to_subattachment
  _type = a["target"]["__typename"]
TypeError: 'NoneType' object has no attribute '__getitem__'

Environment information

Python version 3.7
fbchat version 1.6.4

@femtozer femtozer changed the title Subattachement with no target breaks fetchThreadMessages Subattachment with no target breaks fetchThreadMessages Apr 2, 2019
@madsmtm
Copy link
Member

madsmtm commented Apr 17, 2019

Hmm, just out of curiosity, can you show a screenshot of what the subattachment is supposed to look like in the Messenger UI? But anyhow, you're right, this is a bug, and it should be fairly easy to just skip that subattachment entry

@madsmtm madsmtm added the bug label Apr 17, 2019
@femtozer
Copy link
Author

I unfortunately deleted the message but I think it was a video sharing via facebook to messenger.

madsmtm added a commit that referenced this issue Jun 23, 2019
- Removed / privatized a lot of undocumented functionality, which might break some users application if they were relying on those (hence the minor version bump). See #432 for further reasoning
- Add `Client.forwardAttachment` and `Message.forwarded` attribute, see #420
- Fix parsing subattachments with no target, see #412
- Lots of other refactoring, aka. work on the transition towards v2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants