Browse Source

exchange_rate: cleaner log line for "failed fx quotes"

catch OSError for proxy-related issues (and probably other low level networking)

```
 19.52 | E | exchange_rate.CoinGecko | failed fx quotes: ProxyConnectionError(22, 'Can not connect to proxy localhost:9050 [The remote computer refused the network connection]')
Traceback (most recent call last):
  File "...\Python310\site-packages\python_socks\async_\asyncio\ext\_proxy.py", line 59, in _connect
    await self._stream.open_connection(
  File "...\Python310\site-packages\python_socks\async_\asyncio\ext\_stream.py", line 61, in open_connection
    self._reader, self._writer = await asyncio.open_connection(
  File "...\Python310\lib\asyncio\streams.py", line 48, in open_connection
    transport, _ = await loop.create_connection(
  File "...\Python310\lib\asyncio\base_events.py", line 1076, in create_connection
    raise exceptions[0]
  File "...\Python310\lib\asyncio\base_events.py", line 1060, in create_connection
    sock = await self._connect_sock(
  File "...\Python310\lib\asyncio\base_events.py", line 969, in _connect_sock
    await self.sock_connect(sock, address)
  File "...\Python310\lib\asyncio\proactor_events.py", line 709, in sock_connect
    return await self._proactor.connect(sock, address)
  File "...\Python310\lib\asyncio\windows_events.py", line 826, in _poll
    value = callback(transferred, key, ov)
  File "...\Python310\lib\asyncio\windows_events.py", line 613, in finish_connect
    ov.getresult()
ConnectionRefusedError: [WinError 1225] The remote computer refused the network connection

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "...\electrum\exchange_rate.py", line 85, in update_safe
    self._quotes = await self.get_rates(ccy)
  File "...\electrum\exchange_rate.py", line 345, in get_rates
    json = await self.get_json('api.coingecko.com', '/api/v3/exchange_rates')
  File "...\electrum\exchange_rate.py", line 69, in get_json
    async with session.get(url) as response:
  File "...\Python310\site-packages\aiohttp\client.py", line 1140, in __aenter__
    self._resp = await self._coro
  File "...\Python310\site-packages\aiohttp\client.py", line 535, in _request
    conn = await self._connector.connect(
  File "...\Python310\site-packages\aiohttp\connector.py", line 543, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "...\Python310\site-packages\aiohttp\connector.py", line 906, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "...\Python310\site-packages\aiohttp\connector.py", line 1174, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "...\Python310\site-packages\aiohttp_socks\connector.py", line 58, in _wrap_create_connection
    stream = await proxy.connect(
  File "...\Python310\site-packages\python_socks\async_\asyncio\ext\_proxy.py", line 47, in connect
    await self._connect()
  File "...\Python310\site-packages\python_socks\async_\asyncio\ext\_proxy.py", line 73, in _connect
    raise ProxyConnectionError(e.errno, msg) from e
python_socks._errors.ProxyConnectionError: [Errno 22] Can not connect to proxy localhost:9050 [The remote computer refused the network connection]
```
master
SomberNight 2 years ago
parent
commit
a38e723b40
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 2
      electrum/exchange_rate.py

2
electrum/exchange_rate.py

@ -85,7 +85,7 @@ class ExchangeBase(Logger):
self._quotes = await self.get_rates(ccy)
assert all(isinstance(rate, (Decimal, type(None))) for rate in self._quotes.values()), \
f"fx rate must be Decimal, got {self._quotes}"
except (aiohttp.ClientError, asyncio.TimeoutError) as e:
except (aiohttp.ClientError, asyncio.TimeoutError, OSError) as e:
self.logger.info(f"failed fx quotes: {repr(e)}")
self.on_quotes()
except Exception as e:

Loading…
Cancel
Save