Python API Trouble

Encounter a problem related to the pool or have a request for a feature? Post your issue here and we will help you out.
Forum rules
Welcome to the System Support forum! Encounter a problem related to the pool? Post your issue here and we will help you out.

Keep in mind that the forums are monitored by PROHASHING less closely than the official support channels, so if you have a pressing issue, please submit an official support ticket so that our Support Analyst can look into your issue in a timely manner.

We cannot answer financial questions related to your account on a public forum, so those questions should always be submitted through the orange Support button on prohashing.com/about.

For the full list of PROHASHING forums rules, please visit https://prohashing.com/help/prohashing- ... rms-forums.
Locked
deserteagle
Posts: 1
Joined: Thu Dec 14, 2017 4:16 pm

Python API Trouble

Post by deserteagle » Thu Dec 14, 2017 4:25 pm

I have been trying futilely to convert the call function in the API example from JavaScript to Python. The issue is that I don't think it is accepting my API key parameter. I have tried various encodings of the parameter but the only output I get back when I run this (for the call) is:
<Future finished result=[]>
In other words, I'm getting an empty array back?
On the other hand, the deferred subscription appears to be working as intended. Can anyone help me format the call function so that I get back usable state information that I can use to set the initial state?

Code: Select all

#!/usr/bin/env python3

import ssl
from autobahn.asyncio.wamp import ApplicationSession
from autobahn.asyncio.wamp import ApplicationRunner
from autobahn.wamp import auth
try:
    import asyncio
except ImportError:
    print("Couldn't import asyncio")
    # Trollius >= 0.3 was renamed
    #import trollius as asyncio

user = "web"
secret = "web"

class ProhashingComponent(ApplicationSession):
    def onConnect(self):
        self.join(self.config.realm, [u"wampcra"], user)

    #def onClose(self, wasClean, code, reason):
    #    print("Closing connection")

    def onDisconnect(self):
        print("Force quitting")
        #sendClose(code=1000, reason="User quit")
        asyncio.get_event_loop().stop()

    def onChallenge(self, challenge):
      if challenge.method == u"wampcra":
         print("WAMP-CRA challenge received: {}".format(challenge))

         if u'salt' in challenge.extra:
            # salted secret
            key = auth.derive_key(secret,
                                  challenge.extra['salt'],
                                  challenge.extra['iterations'],
                                  challenge.extra['keylen'])
         else:
            # plain, unsalted secret
            key = secret

         # compute signature for challenge, using the key
         signature = auth.compute_wcs(key, challenge.extra['challenge'])

         # return the signature to the router for verification
         return signature

      else:
         raise Exception("Invalid authmethod {}".format(challenge.method))

    @asyncio.coroutine
    def onJoin(self, details):

        def onAllMinerInit(*args):
            print("**MINER INITIALIZATION**:", args)

            for arg in args:
                print ("another arg:", arg)

            loop = asyncio.get_event_loop()

            # Schedule a call to hello_world()
            loop.call_soon(runSubscription, loop)

        def runSubscription(*args):
            for arg in args:
                print ("another arg:", arg)

            tempX = '282b8...rest...of...api...key...here...5c4dc396'
            self.subscribe(onAllMinerUpdates, 'miner_updates_'+tempX)    
            
        def onAllMinerUpdates(*args):
            for arg in args:
                print ("another arg:", arg)

            print("All miner updates event received:", args)

        def testCoRoutine(myThingToPrint):
            print(myThingToPrint)

        def onProfitabilityUpdates(*args):
            for arg in args:
                print ("another arg:", arg)

            print("Profitability Updates event received:", args)

        try:
            temp_list = []
            temp_list.append("282b8...rest...of...api...key...here...5c4dc396")
            temp_list2 = "['282b8...rest...of...api...key...here...5c4dc396']"
            temp3 = '282b8...rest...of...api...key...here...5c4dc396';
            
            temp4 = {'282b8...rest...of...api...key...here...5c4dc396'}
            temp5 = "{  \"arg1\":[\"282b8...rest...of...api...key...here...5c4dc396\"]}"

            testCoRoutine("Initializing ProHash Python client")
            self.call(u'f_all_miner_updates', temp5).add_done_callback(onAllMinerInit)
            #res = yield from self.call(onAllMinerUpdates, u'f_all_miner_updates_'+temp3)            
            #print("call result: {}".format(res))

            #d2 = self.call(u'f_all_miner_updates', temp_list2)
            #res = yield self.call(u'f_all_miner_updates', temp_list2, options=CallOptions(on_progress=onAllMinerUpdates))               

            #yield from testCoRoutine("Hi there")
            #yield from self.subscribe(onProfitabilityUpdates, 'profitability_updates')
            #await self.subscribe(on_heartbeat, u'com.myapp.heartbeat', options=SubscribeOptions(details_arg='details'))
            #wampSession.call('f_all_miner_updates', ['0a7a6fade943f7b6b9e96b4d1516bfcc733b5158af18d1b43aeec7e45a238c02']).then(initialSessionUpdatesReceived);
            #yield from self.subscribe(onAllMinerUpdates, 'miner_updates_'+temp3)
        except Exception as e:
            print("Could not subscribe to topic:", e)
            print("call error: {0}".format(e))
        except KeyboardInterrupt:
            print("Generated keyboard interrupt")
            pass    
        finally:
            print("Going until we quit.")   

def main():
    context = ssl.create_default_context()
    context.check_hostname = False
    context.verify_mode = ssl.CERT_NONE

    runner = ApplicationRunner(u"wss://live.prohashing.com:443/ws", u"mining", ssl=context)
    #runner = ApplicationRunner(u"wss://prohashing.com:444/ws", u"mining", ssl=context)

    runner.run(ProhashingComponent)

if __name__ == "__main__":
    main()

Locked