BittyTax / BittyTax

Crypto-currency tax calculator with support for all popular wallets, exchanges, explorers and migration from other crypto tax platforms
GNU Affero General Public License v3.0
420 stars 114 forks source link

requests.exceptions.ConnectionError #123

Closed JamesKBowler closed 3 years ago

JamesKBowler commented 3 years ago

Hi,

bittytax v0.4.3
python: v3.8.5
system: Linux, release: 5.8.0-53-generic
config: coinbase_zero_fees_are_gifts = False
config: crypto_list = ['BTC', 'ETH', 'XRP', 'LTC', 'BCH', 'USDT']
config: data_source_crypto = ['CryptoCompare', 'CoinGecko']
config: data_source_fiat = ['ExchangeRatesAPI', 'RatesAPI']
config: data_source_select = {'BTC': ['CoinDesk', 'CryptoCompare']}
config: fiat_list = ['GBP', 'EUR', 'USD']
config: local_currency = GBP
config: show_empty_wallets = False
config: trade_allowable_cost_type = 2
config: trade_asset_type = 2
config: transfer_fee_allowable_cost = False
config: transfer_fee_disposal = False
config: transfers_include = True

When running bittytax -d --taxrules UK_INDIVIDUAL BittyTax_Records.xls it throws the exceptions below.

Also looking at the GET call https://api.ratesapi.io/api/2020-02-16?base=EUR&symbols=GBP the web page is requesting an API key.

What do you think the problem is?

Thanks

price: GET https://api.ratesapi.io/api/2020-02-16?base=EUR&symbols=GBP
Traceback (most recent call last):
  File "/mnt/venv/trading/lib/python3.8/site-packages/urllib3/connection.py", line 169, in _new_conn
    conn = connection.create_connection(
  File "/mnt/venv/trading/lib/python3.8/site-packages/urllib3/util/connection.py", line 73, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/venv/trading/lib/python3.8/site-packages/urllib3/connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
  File "/mnt/venv/trading/lib/python3.8/site-packages/urllib3/connectionpool.py", line 382, in _make_request
    self._validate_conn(conn)
  File "/mnt/venv/trading/lib/python3.8/site-packages/urllib3/connectionpool.py", line 1010, in _validate_conn
    conn.connect()
  File "/mnt/venv/trading/lib/python3.8/site-packages/urllib3/connection.py", line 353, in connect
    conn = self._new_conn()
  File "/mnt/venv/trading/lib/python3.8/site-packages/urllib3/connection.py", line 181, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x7efdfa6e7460>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/venv/trading/lib/python3.8/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/mnt/venv/trading/lib/python3.8/site-packages/urllib3/connectionpool.py", line 755, in urlopen
    retries = retries.increment(
  File "/mnt/venv/trading/lib/python3.8/site-packages/urllib3/util/retry.py", line 573, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.ratesapi.io', port=443): Max retries exceeded with url: /api/2020-02-16?base=EUR&symbols=GBP (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7efdfa6e7460>: Failed to establish a new connection: [Errno -2] Name or service not known'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/venv/trading/bin/bittytax", line 11, in <module>
    load_entry_point('BittyTax==0.4.3', 'console_scripts', 'bittytax')()
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/bittytax.py", line 112, in main
    tax, value_asset = do_tax(transaction_records, args.tax_rules, args.skip_integrity)
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/bittytax.py", line 181, in do_tax
    transaction_history = TransactionHistory(transaction_records, value_asset)
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/transactions.py", line 28, in __init__
    self.get_all_values(tr)
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/transactions.py", line 92, in get_all_values
    tr.buy.cost_fixed) = self.which_asset_value(tr)
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/transactions.py", line 167, in which_asset_value
    value, fixed = self.value_asset.get_value(tr.sell.asset,
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/price/valueasset.py", line 31, in get_value
    asset_price_ccy, _, _ = self.get_historical_price(asset, timestamp)
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/price/valueasset.py", line 71, in get_historical_price
    asset_price_ccy, name, data_source, url = self.price_data.get_historical(asset,
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/price/pricedata.py", line 94, in get_historical
    price, name, url = self.get_historical_ds(data_source, asset, quote, timestamp,
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/price/pricedata.py", line 56, in get_historical_ds
    self.data_sources[data_source.upper()].get_historical(asset, quote, timestamp)
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/price/datasource.py", line 227, in get_historical
    json_resp = self.get_json(url)
  File "/mnt/venv/trading/lib/python3.8/site-packages/bittytax/price/datasource.py", line 43, in get_json
    response = requests.get(url, headers={'User-Agent': self.USER_AGENT}, timeout=self.TIME_OUT)
  File "/mnt/venv/trading/lib/python3.8/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/mnt/venv/trading/lib/python3.8/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/mnt/venv/trading/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/mnt/venv/trading/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "/mnt/venv/trading/lib/python3.8/site-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.ratesapi.io', port=443): Max retries exceeded with url: /api/2020-02-16?base=EUR&symbols=GBP (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7efdfa6e7460>: Failed to establish a new connection: [Errno -2] Name or service not known'))
nanonano commented 3 years ago

Hi @JamesKBowler, thank for raising this, looks like that server has disappeared, hopefully temporarily, as we don't have a backup currently after loosing ExchangeRatesAPI, see https://github.com/BittyTax/BittyTax/issues/102.

JamesKBowler commented 3 years ago

Hi @nanonano, thanks for coming back to me.

I made the change to the bittytax.conf, but getting same errors above.

bittytax v0.4.3
python: v3.8.5
system: Linux, release: 5.8.0-53-generic
config: coinbase_zero_fees_are_gifts = False
config: crypto_list = ['BTC', 'ETH', 'XRP', 'LTC', 'BCH', 'USDT']
config: data_source_crypto = ['CryptoCompare', 'CoinGecko']
config: data_source_fiat = ['RatesAPI']
config: data_source_select = {'BTC': ['CoinDesk', 'CryptoCompare']}
config: fiat_list = ['GBP', 'EUR', 'USD']
config: local_currency = GBP
config: show_empty_wallets = False
config: trade_allowable_cost_type = 2
config: trade_asset_type = 2
config: transfer_fee_allowable_cost = False
config: transfer_fee_disposal = False
config: transfers_include = True
nanonano commented 3 years ago

Looks like RatesApi (our secondary fiat data source) is no longer available, and is re-directing to ExchangeRatesApi (our primary fiat data source) which we stopped using due to the paid subscription, and the free one have limited usage.

Screenshot 2021-05-22 at 10 43 20

Decided that BittyTax will host it's own fiat exchange rates server (BittyTaxAPI), I'm working on this at the moment and hope to have something up and running very soon. This will become the primary fiat data source, with the ExchangeRatesAPI becoming the secondary, but users will have to register for an API Key for that one, and usage will be limited.

The BittyTaxAPI server will be free to use and require no API key.

JamesKBowler commented 3 years ago

I suspected that was the case. Thanks for building this application, once I have my accounts reconciled i'll focus more on making this super cool and help out where I can. The audit feature on this is shit hot, I've tried a few online tax services and they are locked down with features I either don't want or don't have. At least with this application extra stuff can be added, so much potential.

Thanks again.

nanonano commented 3 years ago

Thanks @JamesKBowler any help you can give would be most appreciated! I've got lots of features in the works, just takes time to test, integrate and document everything, I agree this project has a lot of potential, would like to do better with the DeFi stuff as that's just going to grow and grow, add blockchain integration, etc.

I've added another data source for fiat prices while I work on getting our own server up and running, see https://github.com/BittyTax/BittyTax/commit/d2dde150d2f66b7434e04b39ee79eec841cd4308.

JamesKBowler commented 3 years ago

awesome thanks!

Wauter commented 3 years ago

Seems like I ran into this issue. I am a new user to the software, when I tried to use bittytax_conv on a supported file format, I got the message: WARNING File could not be read: ***.xlsx (however the debug options did show the header and first row decoded fine) After a bit of digging, I came across this issue. The alternative apis I found did not work and I needed this now, so I caved and subscribed to exchangerateapis for a month. I hacked the api key into the url and that seems to do the trick fine.

Its fantastic that you are setting up a free of charge rate api for the application, but it seems in the interim, it is completely broken due to this 3th party issue? Maybe option is required to use a paid subscription.

(And maybe better failure message would be good, I spend a fair amount of time checking my file and file permissions..)

nanonano commented 3 years ago

Hi @Wauter, glad you found what the issue was, the BittyTaxAPI is up and running, I'm just doing some final checks before I announcement it publicly https://stats.uptimerobot.com/N1rpVcNGMw.

Which version were you running, when you got the confusing error message? Was it the pip installed version or the latest from GitHub? Also what type of file data file where to converting with the conv tool which caused the error?

nanonano commented 3 years ago

@Wauter did you try the Frankfurter API here? https://github.com/BittyTax/BittyTax/commit/d2dde150d2f66b7434e04b39ee79eec841cd4308

Wauter commented 3 years ago

I didn't, didn't come across that info while trying to resolve my issue. Neither the configuration that I had nor the readme mentions this api? That's just some feedback, I was able to do what I came here for, thank you very much.

Hi @Wauter, glad you found what the issue was, the BittyTaxAPI is up and running, I'm just doing some final checks before I announcement it publicly https://stats.uptimerobot.com/N1rpVcNGMw.

Which version were you running, when you got the confusing error message? Was it the pip installed version or the latest from GitHub? Also what type of file data file where to converting with the conv tool which caused the error?

I tried to do a little bit of debugging on it, that specific error is caused when I pull and build the latest code, while still using an old configuration file. (you see, I downloaded bittytax a good while ago but ended up not using it until now, i upgraded before trying). See console output below for details.

After I nuke the old configuration and the new build makes a new config file, I can see Frankfurther api present in the config and the specific error goes away. It does throw a new error, looks like ccy-rate is None or something. (I got that message earlier too, while getting a bad response from ratesapi, but I can see the frankfurther api is returning data fine). Anyway, hope this helps. My config is probably f-ed and if you can't reproduce I wouldn't worry, I'll start fresh next time i run it. console.txt test.csv

johnuopini commented 3 years ago

This change works!!!

laurango commented 3 years ago

Really appreciate all you are doing for the community, @nanonano - building out your own fiat FX server API shows yet again your dedication! I dropped you a small 'coffee' as a thank you.

nanonano commented 3 years ago

Thank you so much @laurango for the donation, really appreciated!