Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python bindings: Logout MegaRequest #87

Closed
nar6du14 opened this issue May 18, 2015 · 2 comments
Closed

python bindings: Logout MegaRequest #87

nar6du14 opened this issue May 18, 2015 · 2 comments

Comments

@nar6du14
Copy link

Hello I try to learn mega at this moment
so I did a little prog:

 #-*- encoding: utf-8 -*-

import sys
import os
import cmd
import time

_wrapper_dir = os.getcwd()
_libs_dir = os.path.join(_wrapper_dir, '.libs')
_shared_lib = os.path.join(_libs_dir, '_mega.so')
if os.path.isdir(_wrapper_dir) and os.path.isfile(_shared_lib):
    sys.path.insert(0, _wrapper_dir)  # mega.py
    sys.path.insert(0, _libs_dir)     # _mega.so

from mega import *

class Listner(MegaListener):

      def __init__(self, v, api):
          self.v = v
          super(Listner, self).__init__()

      def onRequestStart(self, *args):
          print "request: {}".format(args[1])

      def onRequestFinish(self, *args):
          api, req, err = args[:3]
          cod = err.getErrorCode()
          print "request {} finished".format(req.toString())
          print cod == MegaRequest.TYPE_LOGIN
          if cod == MegaError.API_OK:      
             if cod == MegaRequest.TYPE_LOGIN:
                print "ama"
                api.logout()
          if cod != MegaError.API_OK or req.getType == MegaRequest.TYPE_LOGOUT:
             print "an error occurs: {}".format(err.tostring())
             print "ici"
             self.v[0] = 0



if __name__ == "__main__":
   v = [1]
   api = MegaApi("myappkey")
   li = Listner(v, api)
   api.addListener(li)
   api.login("myemail", "mypassword") 
   while v[0]:
         time.sleep(0.5)
         print v[0]
   print "ended"

but I have noticed that "print cod == MegaRequest.TYPE_LOGIN" return true
when sending a "logout" command I think it should be MegaRequest.TYPE_LOGOUT no "MegaRequest.TYPE_LOGIN"

@javiserrano
Copy link
Contributor

Hello.

Thank you for using our SDK!
It seems that you are comparing the error code (cod = err.getErrorCode()) with the request type (MegaRequest.TYPE_LOGIN). You should use req.getType() to know the request type.

@nar6du14
Copy link
Author

ok, thanks

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

No branches or pull requests

2 participants