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

fix get_messages method #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 10 additions & 20 deletions client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import requests
import sseclient
import json
import os
from time import sleep
Expand Down Expand Up @@ -39,25 +38,16 @@ def get_messages(self):

while True:
try:
response = requests.get(url, stream=True)
if 'Content-Type' in response.headers:
client = sseclient.SSEClient(response)

print('connected successfully\n')

for event in client.events():
try:
message_event = json.loads(event.data)
yield message_event
except Exception as e:
print(e.args[0])
continue
else:
print('Invalid bot token OR Invalid connection response from server')

print('retry to connect after 10 seconds...')
sleep(self.RETRY_DELAY)

session = requests.Session()
with session.get(url, headers=None, stream=True) as resp:
for line in resp.iter_lines():
if line:
try:
message_event = json.loads(line.decode("utf-8")[5::])["body"]
yield message_event
except Exception as e:
print(e.args[0])
continue
except Exception as e:
print(e.args[0])
print('retry to connect after 10 seconds...')
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
requests
sseclient-py