steemit / steem-python

The official Python (3) library for the Steem Blockchain.
https://steem.io
MIT License
154 stars 99 forks source link

Exceptions When Streaming Comments #108

Closed kharoof closed 6 years ago

kharoof commented 6 years ago

I have tried various attempts at streaming blockchain posts and issuing a command on pre defined events via a python script using the steem-python package (i.e. vote on posts or add a comment when certain conditions are met) but I keep running into the issue where the python script I am running crashes. This is really annoying and I have tried several implementations

My latest implementation is as follows

#create a steemd instance steemd_instance = Steem(keys=[posting_key], nodes=my_nodes) #Stream the comments stream = steemd_instance.stream_comments() #Iterate through the comments s = next(stream) #When a condition is met try to upvote or comment s.upvote(default_vote, account)

This code keeps having exceptions at the stage where I try to vote or comment which means I miss votes or miss comments. I have tried catching the error, waiting 5 seconds and trying again but it just fails again.

I am running python3.6 on a rasberry pi running raspbian and the steem package version is steem (0.18.103)

E-D-A commented 6 years ago

Sounds like the exception you have has nothing to do with the fact that you streaming comments. Can you please post the exception you are getting?

Also, I would recommend not using stream_comments(). It automatically returns a Post object for each streamed post. This causes a lot of overhead as an extra API call is performed every single time. Better to do some filtering and call Post() when needed. stream_comments() is using the stream() function in Blockchain. So you could look at using that instead.

KylePiira commented 6 years ago

Experiencing similar error using stream_comments() also getting a error when using other Blockchain module actions. Tested on multiple networks.

>>> from steem import Steem
>>> s = Steem(nodes=['https://api.steemit.com'])
>>> for post in s.stream_comments():
...     print(post.title)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/kyle/Code/Django/env/local/lib/python3.6/site-packages/steem/steemd.py", line 132, in stream_comments
    ).stream("comment", *args, **kwargs):
  File "/home/kyle/Code/Django/env/local/lib/python3.6/site-packages/steem/blockchain.py", line 177, in stream
    for ops in self.stream_from(*args, **kwargs):
  File "/home/kyle/Code/Django/env/local/lib/python3.6/site-packages/steem/blockchain.py", line 74, in stream_from
    head_block = self.get_current_block_num()
  File "/home/kyle/Code/Django/env/local/lib/python3.6/site-packages/steem/blockchain.py", line 42, in get_current_block_num
    return self.info().get(self.mode)
  File "/home/kyle/Code/Django/env/local/lib/python3.6/site-packages/steem/blockchain.py", line 34, in info
    return self.steem.get_dynamic_global_properties()
  File "/home/kyle/Code/Django/env/local/lib/python3.6/site-packages/steem/steemd.py", line 410, in get_dynamic_global_properties
    return self.exec('get_dynamic_global_properties', api='database_api')
  File "/home/kyle/Code/Django/env/local/lib/python3.6/site-packages/steembase/http_client.py", line 186, in exec
    return_with_args=return_with_args)
  File "/home/kyle/Code/Django/env/local/lib/python3.6/site-packages/steembase/http_client.py", line 206, in _return
    raise RPCError(error_message)
steembase.exceptions.RPCError: Internal Error
cryptocifer commented 6 years ago

seems api.steemit.com is not so stable than former steemd.steemit.com

KylePiira commented 6 years ago

@cifer-lee Its a shame that they depreciated their stable node before properly testing the new one with all of their own official modules.

cryptocifer commented 6 years ago

@KylePiira all right

sneak commented 6 years ago

It is the responsibility, for now, of client code to handle such exceptions and restart streaming.

PRs to make steem-python work better and handle this sort of retrying internally would likely get merged if they are up to our code standards, which unfortunately aren't well-documented yet but are approximately "use pep8 and pyflakes".