Skip to content

Subattachment with no target breaks fetchThreadMessages #412

@femtozer

Description

@femtozer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions