Repository: rotki/rotki

Issue:
Rotki failed to start - errors pulling data and no accounts showing up
After signing in, no balances are populating and receiving following errors:

The backend query task died unexpectedly: Could not find a suitable TLS CA certificate bundle, invalid path: C:\Users\XXXXBA~1\AppData\Local\Temp\_MEI204762\certifi\cacert.pem

Querying blockchain balances died because of: The backend query task died unexpectedly: Could not find a suitable TLS CA certificate bundle, invalid path: C:\Users\XXXXBA~1\AppData\Local\Temp\_MEI204762\certifi\cacert.pem. Check the logs for more details.

Exchange Rates   Failed fetching exchange rates: Request failed with status code 500




Discussion:
Hey @BigPapa0. Thank you for trying Rotki out and for the issue report.

Well that sounds strange and I have never seen it before. I will need some more information first in order to have somewhere to start from. Can you answer the following?

1. Is this the first time you ever ran Rotki? Have you ran it before and was it working fine?
2. I assume you are running Windows. Which version? Also which version of Rotki are you running?
3. Rotki starts fine, you log in succesfully but the problem is when you query balances/exchanges and not at login/start, right?
4. Can you please attach the rotkehlchen log and the rotki electron log of this run? They should be under: `%APPDATA%/rotki/`
1. Not the first time, it was working fine before. Although a "Rotki failed to start" message appears at the bottom most times even when balances are pulling ok. 
2. Windows 10. Rotki version v1.1.1
3. It starts fine. I can login with username and password and then I get the errors and nothing is showing up. 
4. Attached is the log, although I just tried it again and didn't get the errors.  So I don't have the log file when I saw the errors. Although now my addresses aren't saved, only the exchange api I added.
[rotkehlchen.log](https://github.com/rotki/rotki/files/4210668/rotkehlchen.log)


All right, so the address problem now according to the log is that you don't have an Etherscan API key. Since yesterday etherscan introduced compulsory api keys. Can you please go and make an account with them and get a free api key and add it in the API keys of Rotki?

I also see that this problem can be addressed more gracefully from the logs. Will fix that.
```
16/02/2020 14:12:08 Eastern Standard Time -- ERROR:rotkehlchen.rotkehlchen:Querying blockchain balances failed due to: Etherscan has introduced compulsory API keys from 15/02/2020.Please go to to https://etherscan.io/register, create an API key and then input it in the ex>
16/02/2020 14:12:08 Eastern Standard Time -- ERROR:rotkehlchen.api.rest:Greenlet for task 0 dies with exception: local variable 'blockchain_result' referenced before assignment.
Exception Name: <class 'UnboundLocalError'>
Exception Info: local variable 'blockchain_result' referenced before assignment
Traceback:
   File "src/gevent/greenlet.py", line 818, in gevent._greenlet.Greenlet.run
  File "rotkehlchen\api\rest.py", line 201, in _do_query_async
  File "rotkehlchen\api\rest.py", line 300, in _query_all_balances
  File "rotkehlchen\rotkehlchen.py", line 415, in query_balances

16/02/2020 14:12:10 Eastern Standard Time -- DEBUG:rotkehlchen.api.rest:Request successful response={"result": {"status": "completed", "outcome": {"result": null, "message": "The backend query task died unexpectedly: local variable 'blockchain_result' referenced before as>
16/02/2020 14:12:10 Eastern Standard Time -- INFO:rotkehlchen.api.server.pywsgi:127.0.0.1 - - [2020-02-16 14:12:10] "GET /api/1/tasks/0 HTTP/1.1" 200 388 0.003000
```

> Attached is the log, although I just tried it again and didn't get the errors.

That's good for you, but bad for debugging. I suspect it was something temporary with your Windows system at the time. If it happens again please get the logs and post them here.

Resolving patch:
diff --git a/rotkehlchen/rotkehlchen.py b/rotkehlchen/rotkehlchen.py
--- a/rotkehlchen/rotkehlchen.py
+++ b/rotkehlchen/rotkehlchen.py
@@ -409,14 +409,13 @@ def query_balances(
                 blockchain=None,
                 ignore_cache=ignore_cache,
             )
+            balances['blockchain'] = {
+                asset: balance.to_dict() for asset, balance in blockchain_result.totals.items()
+            }
         except (RemoteError, EthSyncError) as e:
             problem_free = False
             log.error(f'Querying blockchain balances failed due to: {str(e)}')
 
-        balances['blockchain'] = {
-            asset: balance.to_dict() for asset, balance in blockchain_result.totals.items()
-        }
-
         result = self.query_fiat_balances()
         if result != {}:
             balances['banks'] = result


Test patch: