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

fetchThreadList error due to invalid value for ThreadColor #379

Closed RodriguesGabriel closed 5 years ago

RodriguesGabriel commented 5 years ago

Description of the problem

When fetching thread list ValueError and FBchatException are raised probably due to the recently-introduced new Messenger colors (gradients).

Code to reproduce

# Example code
from fbchat import Client
client = Client("[REDACTED_USERNAME]", "a_password_with_%")
client.fetchThreadList()

Traceback

Traceback (most recent call last):
  File "C:\...\venv\lib\site-packages\fbchat\graphql.py", line 32, in graphql_color_to_enum
    return ThreadColor('#{}'.format(color[2:].lower()))
  File "C:\ProgramData\Anaconda3\lib\enum.py", line 309, in __call__
    return cls.__new__(cls, value)
  File "C:\ProgramData\Anaconda3\lib\enum.py", line 543, in __new__
    return cls._missing_(value)
  File "C:\ProgramData\Anaconda3\lib\enum.py", line 556, in _missing_
    raise ValueError("%r is not a valid %s" % (value, cls.__name__))
ValueError: '#0edcde' is not a valid ThreadColor

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\...\venv\lib\site-packages\fbchat\client.py", line 890, in fetchThreadList
    return [graphql_to_thread(node) for node in j['viewer']['message_threads']['nodes']]
  File "C\...\venv\lib\site-packages\fbchat\client.py", line 890, in <listcomp>
    return [graphql_to_thread(node) for node in j['viewer']['message_threads']['nodes']]
  File "C\...\venv\lib\site-packages\fbchat\graphql.py", line 246, in graphql_to_thread
    return graphql_to_group(thread)
  File "C:\...\venv\lib\site-packages\fbchat\graphql.py", line 291, in graphql_to_group
    c_info = get_customization_info(group)
  File "C:\...\venv\lib\site-packages\fbchat\graphql.py", line 43, in get_customization_info
    'color': graphql_color_to_enum(info.get('outgoing_bubble_color'))
  File "C:\...\venv\lib\site-packages\fbchat\graphql.py", line 34, in graphql_color_to_enum
    raise FBchatException('Could not get ThreadColor from color: {}'.format(color))
fbchat.models.FBchatException: Could not get ThreadColor from color: FF0EDCDE

Environment information

As a quick fix I commented graphql.py line 43 where graphql_color_to_enum was called.

madsmtm commented 5 years ago

Should be fixed by #371, I'll make a new release momentarily :wink: