Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.9.5
current_version = 1.9.7
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion examples/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@

# Print image url for 20 last images from thread.
images = client.fetchThreadImages("<thread id>")
for image in islice(image, 20):
for image in islice(images, 20):
print(image.large_preview_url)
2 changes: 1 addition & 1 deletion fbchat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ._util import log # TODO: Remove this (from examples too)

__title__ = "fbchat"
__version__ = "1.9.5"
__version__ = "1.9.7"
__description__ = "Facebook Chat (Messenger) for Python"

__copyright__ = "Copyright 2015 - 2019 by Taehoon Kim"
Expand Down
11 changes: 6 additions & 5 deletions fbchat/_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ def _fetch_sequence_id(state):
log.debug("Fetching MQTT sequence ID")
# Same request as in `Client.fetchThreadList`
(j,) = state._graphql_requests(_graphql.from_doc_id("1349387578499440", params))
try:
return int(j["viewer"]["message_threads"]["sync_sequence_id"])
except (KeyError, ValueError):
# TODO: Proper exceptions
raise
sequence_id = j["viewer"]["message_threads"]["sync_sequence_id"]
if not sequence_id:
raise _exception.FBchatNotLoggedIn("Failed fetching sequence id")
return int(sequence_id)

def _on_connect_handler(self, client, userdata, flags, rc):
if rc == 21:
Expand Down Expand Up @@ -287,6 +286,8 @@ def loop_once(self, on_error=None):
# This error is wrongly classified
# See https://github.com/eclipse/paho.mqtt.python/issues/340
log.warning("Connection error, retrying")
elif rc == paho.mqtt.client.MQTT_ERR_CONN_REFUSED:
raise _exception.FBchatNotLoggedIn("MQTT connection refused")
else:
err = paho.mqtt.client.error_string(rc)
log.error("MQTT Error: %s", err)
Expand Down
2 changes: 2 additions & 0 deletions fbchat/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def find_input_fields(html):
def session_factory(user_agent=None):
session = requests.session()
session.headers["Referer"] = "https://www.facebook.com"
session.headers["Accept"] = "text/html"

# TODO: Deprecate setting the user agent manually
session.headers["User-Agent"] = user_agent or random.choice(_util.USER_AGENTS)
return session
Expand Down