Problem with the python2 rest streaming sample code


Granted, I’m definitely no Python wiz, but am I not supposed to get some output from the REST streaming code example? The Curl version works just fine but I can’t seem to get the Python 2 example to output anything. And yes, I have included the correct token :slight_smile: Any suggestions greatly appreciated.
Talking about this one:


When you say “to output anything” what do you mean exactly… while it’s running, if you change something on whatever device you authorized it doesn’t output “the data has changed” or anything like that?


sorry for being vague. if i run the curl statement i get the expected event : put data{… when something happens and the event: keep-alive when nothing is going on. if i run the python example it just dumps me back to the command line. i had expected it to “listen” like the curl example. but perhaps i’m mistaken?


Hi jonas,
For this sample, you would need to install sseclient-py (not sseclient). However it still is imported as ‘sseclient’ in the code. You probably have installed, which is similar enough to not have any error messages within this sample, but unfortunately doesn’t work with it :frowning:
To use the Python 2 (or 3) code example, you will need to install

pip install sseclient-py


thank you very much for your reply becky however, unfortunately it was’t quite that easy as i already have sseclient-py installed.


Thanks jonas. We will check if something has changed with the libraries or environment and add a note or update the sample.


Hi jonas,
There was a default setting that changed so we will be updating the samples soon. If you prefer you can try this change:

replace this line of code in the sample:
response = http.request(‘GET’, url, headers=headers, preload_content=False)

with the following code:
response = http.request(‘GET’, url, headers=headers, preload_content=False, redirect=False)
if (response.status == 307):
redirect_url = response.headers.get(“Location”)
response = http.request(‘GET’, redirect_url, headers=headers,
preload_content=False, redirect=False)
if (response.status != 200):
print "An error occurred! Response code is ", response.status

Thanks for hanging in there on this and finding this issue!


works perfectly. thank you!