Skip to content
This repository has been archived by the owner on Jul 20, 2020. It is now read-only.

error code 10100 (auth: invalid) #49

Closed
lucasjota opened this issue Sep 18, 2017 · 14 comments
Closed

error code 10100 (auth: invalid) #49

lucasjota opened this issue Sep 18, 2017 · 14 comments
Assignees
Labels

Comments

@lucasjota
Copy link

Hello!,

When receiving this error, connection keeps working but only for unauthenticated channels.
Patched it like this:

=== modified file 'connection.py'
--- connection.py       2017-09-18 00:47:35 +0000
+++ connection.py       2017-09-18 01:55:39 +0000
@@ -47,6 +47,7 @@
 
         # Connection Handling Attributes
         self.connected = Event()
+        self.needsreauth = Event()
         self.disconnect_called = Event()
         self.reconnect_required = Event()
         self.reconnect_interval = reconnect_interval if reconnect_interval else 10
@@ -389,6 +390,7 @@
         """
         errors = {10000: 'Unknown event',
                   10001: 'Unknown pair',
+                  10100: 'Auth invalid',
                   10300: 'Subscription Failed (generic)',
                   10301: 'Already Subscribed',
                   10302: 'Unknown channel',
@@ -401,6 +403,8 @@
             # Unknown error code, log it and reconnect.
             self.log.error("Received unknown error Code in message %s! "
                            "Reconnecting..", data)
+        if data['code'] == 10100:
+            self.needsreauth.set()
 
     def _data_handler(self, data, ts):
         """Handles data messages by passing them up to the client.

So it is possible to check and solve from BtfxWss instance if wanted/necessary:

if self.conn.needsreauth.is_set():
  self.authenticate()

After reconnect, all keeps smooth again.

Best Regards,

@deepbrook deepbrook added the bug label Sep 18, 2017
@deepbrook deepbrook self-assigned this Sep 18, 2017
@alexeykarnachev
Copy link
Contributor

Hello!
nlsdfnbch, I need this bug-fix asap =)
Could you please advice me the best way from your point of view to fix it. I'll try to make the patch yesterday.

@deepbrook
Copy link
Collaborator

Thanks @alexeykarnachev! I'm working on it already, tho. It should be deployed in the next few hours. The thing is, we need to move the authentication to the connection class, because we'd have to otherwise hold a reference to the client in connection, which just isn't very nice to look at. If you have a better suggestion, don't hesitate to share!

deepbrook pushed a commit that referenced this issue Sep 19, 2017
@deepbrook
Copy link
Collaborator

It's not as pretty as I'd like - the whole way the resubscription is being handles could be better, but the above commit should fix the issue nonetheless.

I / we should perhaps look into a better way to implement this. Could you verify this is working now @lucasjota , @alexeykarnachev ? Use the dev branch, as the fix isnt on prod yet.

@alexeykarnachev
Copy link
Contributor

Cool. I'll check it in next hour, but I need a way to simulate an authintification lost. Any ideas?

@deepbrook
Copy link
Collaborator

..authenticate with the api, pull the ethernet cable and reconnect it again? :'D That'd be easiest I can think of for an interrupted connection. I think that would work.

@alexeykarnachev
Copy link
Contributor

Just tried it:
Got the following message
ERROR:btfxwss.connection:Received unknown error Code in message {'code': 10100, 'msg': 'auth: invalid'}! Reconnecting..
Unfortunately it's hard to obtain logs. I switched them off, because there is tremendous amount of them (raw books, trades and so on)

@alexeykarnachev
Copy link
Contributor

alexeykarnachev commented Sep 19, 2017

Oh, ok =) It's because there is no such code in codes dict.

UPD:
But the issue still exists I think.
_error_handler() method contains only logging and I think it's not a problem that the key is not presented in the dict.
It looks like re-connection was not performed

UPD2:
Look at this line in connection.py

auth_sig = hmac.new(self.secret.encode(), auth_string.encode(), hashlib.sha384).hexdigest()

I can not find hmac and hashlib in imports.

deepbrook pushed a commit that referenced this issue Sep 19, 2017
@deepbrook
Copy link
Collaborator

Yes, that's because I'm a nugget and forgot them. fixed that.

@alexeykarnachev
Copy link
Contributor

Tried it again,
Re-auth still does not work =)

@alexeykarnachev
Copy link
Contributor

Here is another thing which looks like a bug:

connection.py (262:266)

        auth_sig = hmac.new(self.secret.encode(), auth_string.encode(),
                            hashlib.sha384).hexdigest()

        payload = {'event': 'auth', 'apiKey': self.key, 'authSig': auth_sig,
                   'authPayload': auth_string, 'authNonce': nonce}

self.key and self.secret does not exist. Maybe, ".self" should be removed ?

@deepbrook
Copy link
Collaborator

of course they should be. I don't know what's going on with me today. You make a great debugger, tho ;D

@alexeykarnachev
Copy link
Contributor

alexeykarnachev commented Sep 19, 2017

Hmmm.
Look:

    if auth:
        nonce = str(int(time.time() * 10000000))
        auth_string = 'AUTH' + nonce
        auth_sig = hmac.new(secret.encode(), auth_string.encode(),
                            hashlib.sha384).hexdigest()

        payload = {'event': 'auth', 'apiKey': key, 'authSig': auth_sig,
                   'authPayload': auth_string, 'authNonce': nonce}
      
      *******************************************************************************************
       *** This payload will be never send  because of the next if-else statement***

    if list_data:
        payload = json.dumps(list_data)
    else:
        payload = json.dumps(kwargs)
    .......................

I Think it could be fixed by changing if list_data: to ifels list_data:

And of course don't forget to add json.dumps(payload)

deepbrook pushed a commit that referenced this issue Sep 19, 2017
@deepbrook
Copy link
Collaborator

looking back, probably wouldve been faster if you had implemented it - I'm coding with my ass today. Fixed that!

@alexeykarnachev
Copy link
Contributor

Ok, sure.
Actually it looks like it was the last fix.
Just tried and I think it works. Anyway, if I'll find any bugs, I'll make pull request.
thx!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants