priestc / moneywagon

Universal bitcoin/altcoin blockchain client library for Python and the command line
http://multiexplorer.com
MIT License
149 stars 48 forks source link

recover gracefully on ssl error #4

Closed shivaenigma closed 8 years ago

shivaenigma commented 8 years ago
(blockonomics)enigma@enigma-laptop:~/btxfees$ python main.py 1LuckyG4tMMZf64j6ea7JhCz7sDpk6vdcS -a 1.5
* Trying: <Service: CoinPrism (0 in cache)> btc 1luckyg4tmmzf64j6ea7jhcz7sdpk6vdcs
Traceback (most recent call last):
  File "main.py", line 32, in <module>
    main()
  File "main.py", line 29, in main
    get_txout(args.addresses)
  File "main.py", line 14, in get_txout
    get_unspent_outputs('btc', addr, random=True, verbose=True)
  File "/home/enigma/venvs/blockonomics/local/lib/python2.7/site-packages/moneywagon/__init__.py", line 53, in get_unspent_outputs
    services, UnspentOutputs, {'crypto': crypto, 'address': address}, modes=modes
  File "/home/enigma/venvs/blockonomics/local/lib/python2.7/site-packages/moneywagon/core.py", line 310, in enforce_service_mode
    return FetcherClass(services=services, verbose=verbose).action(**kwargs)
  File "/home/enigma/venvs/blockonomics/local/lib/python2.7/site-packages/moneywagon/__init__.py", line 223, in action
    return self._try_services('get_unspent_outputs', crypto=crypto, address=address)
  File "/home/enigma/venvs/blockonomics/local/lib/python2.7/site-packages/moneywagon/core.py", line 247, in _try_services
    ret =  getattr(service, method_name)(*args, **kwargs)
  File "/home/enigma/venvs/blockonomics/local/lib/python2.7/site-packages/moneywagon/services.py", line 501, in get_unspent_outputs
    for tx in self.get_url(url).json():
  File "/home/enigma/venvs/blockonomics/local/lib/python2.7/site-packages/moneywagon/core.py", line 44, in get_url
    return self._external_request('get', url, *args, **kwargs)
  File "/home/enigma/venvs/blockonomics/local/lib/python2.7/site-packages/moneywagon/core.py", line 66, in _external_request
    response = getattr(requests, method)(url, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in get
    return request('get', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 383, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 486, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 385, in send
    raise SSLError(e)
requests.exceptions.SSLError: hostname 'api.coinprism.com' doesn't match either of 'www.coinprism.com', 'coinprism.com'

Expected: FAIL and try next service Also request timeout seems too large , maybe set to 3sec or give an option to set timeout

priestc commented 8 years ago

Thank you for reporting this issue. These types of problems are hard to deal with. One moment the server is returning an SSL error, the next moment the problem goes away... BTW if you upgrade to verson 1.8.2 there is a timeout keyword argument to get_unspent_outputs you can use...