huwwp / cryptop

command line crypto portfolio
MIT License
235 stars 40 forks source link

"Could not complete request" #44

Open jgoggan opened 7 years ago

jgoggan commented 7 years ago

So, fairly regularly (at least once every 24 hours and often every hour or so), my Cryptop will die. It dumps "Could not complete request" and just ends. It's like a temporary issue pulling the data isn't caught as an exception or something.

I'm running 0.1.9 under Windows 10. Using GitHub Desktop to grab things and Python v3.6.2.

Actually, now that I look at the code, I see that it is indeed that. In get_price(), it tries to pull the coin data from cryptocompare and, if it gets an exception there, it just exits. Wouldn't this be fairly common that there is a temporary internet issue and/or cryptocompare is having a small issue and that request might fail? Seems like it would be better to just retry again?

Thanks!

nrenich commented 7 years ago

I'm getting lots of these too, running on Ubuntu 16.04 w/Python 3.5.2. I have 100MB internet. Some times it will run all day, other times it will crash several times a day.

jgoggan commented 7 years ago

Good to hear it isn't just me -- and isn't a Windows problem. It appears to be an issue when cryptocompare can't be reached momentarily.

Just for testing, I hacked in a little code to create a Request.Session since it supports retries. Since then, I haven't had it die yet. (It will if the retries go over 10 like if it is down for an extended period -- but it seems to get around the little hiccup issues like we're seeing.)

So, if someone wants to quick add it in, something like this works:

    fmt = 'https://min-api.cryptocompare.com/data/pricemultifull?fsyms={}&tsyms={}'

    s = requests.Session()
    https_retries = Retry(total=10)
    https = requests.adapters.HTTPAdapter(max_retries=https_retries)
    s.mount('https://', https)

    try:
        r = s.get(fmt.format(coin, curr))

That would be in place of these existing lines:

    fmt = 'https://min-api.cryptocompare.com/data/pricemultifull?fsyms={}&tsyms={}'

    try:
         r = requests.get(fmt.format(coin, curr)) '''

And you may need to add the import of Retry too:

from requests.packages.urllib3 import Retry

UnbendableStraw commented 6 years ago

Having the same issue, can't figure out how to implement the mentioned fix above