dimanche 5 novembre 2017

Wamp-cra. Script does not connect to the server

The problem is that I have a js script that should connect to the Wamp server. This script works and gets the data I need. Now the task is to rewrite this script in python. I rewrote it, but it does not work. I can not understand what the problem is.

This script works

    <html>
<head>
<script>AUTOBAHN_DEBUG = false;</script>
 <script src="./autobahn.min.js"></script>
<meta charset="utf-8" />
</head>
<body>

<script>
    var wampSession = null;
    var wampUser = 'web';
    var wampPassword = 'web';
    function onChallenge(wampSession, method, extra) {
        if (method == 'wampcra') {
            return autobahn.auth_cra.sign(wampPassword, extra.challenge);
        }
    };

    function connectionOpen(session) {
        wampSession.call('f_all_profitability_updates');
    };


    var wampConnection = new autobahn.Connection({
        url : 'wss://live.prohashing.com:443/ws',
        realm : 'mining',
        authmethods: ['wampcra'],
        authid: 'web',
        onchallenge: onChallenge
    });

    wampConnection.onopen = function (session) {
    session.call('f_all_profitability_updates').then(
      function (res) {
            var a=(res[1].max_btc);
            var b=Number(res[4].max_btc);
         console.log("Result:",a,b);
      }
   );
};
    wampConnection.open();  
</script>
    </body>
</html>

This script does not connect to the server. If it were connected, it would display the message "ok, session joined!"

import os
import sys

from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks

from autobahn.twisted.wamp import ApplicationSession
from autobahn.wamp.types import PublishOptions
from autobahn.wamp import auth


class MyFrontendComponent(ApplicationSession):

    def onConnect(self):
        print("ok, session joined!")
        self.join(u"mining", [u"wampcra"], u"web")

    def onChallenge(self, challenge):
        if challenge.method == u"wampcra":
            signature = auth.compute_wcs(u"web",
                                      challenge.extra['challenge'])
            return signature
        else:
            raise Exception("don't know how to handle authmethod {}".format(challenge.method))

    def onJoin(self, details):
        print("ok, session joined!")

if __name__ == '__main__':
    from autobahn.twisted.wamp import ApplicationRunner
    runner = ApplicationRunner(url=u'wss://live.prohashing.com:443/ws', realm=u'mining')
    runner.run(MyFrontendComponent)




Aucun commentaire:

Enregistrer un commentaire