Skip to content

Instantly share code, notes, and snippets.

@rsyring
Last active June 8, 2018 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsyring/7a05cb2fed60bc92d4ecf6ab75c4aedd to your computer and use it in GitHub Desktop.
Save rsyring/7a05cb2fed60bc92d4ecf6ab75c4aedd to your computer and use it in GitHub Desktop.
Streaming salt-api events using python requests
import requests
import arrow
session = requests.Session()
resp = session.post(
'http://172.18.0.3:8765/login',
json={
'username': 'tang-api',
'password': 'notsecure',
'eauth': 'pam',
},
)
data = resp.json()['return'][0]
token = data['token']
expire = arrow.get(data['expire'])
print(f'Token {token} expires: {expire.humanize()}')
resp = session.get('http://172.18.0.3:8765/', json=[{
'client': 'local',
'tgt': '*',
'fun': 'test.ping'
}])
print(resp.json())
with session.post('http://172.18.0.3:8765/events', stream=True) as r:
for line in r.iter_lines(decode_unicode=True):
print(line)
if r.status_code != 200:
print(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment