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 - MegaNode.getChildren() always returns None #2655

Open
ggpwnkthx opened this issue Oct 24, 2023 · 1 comment
Open

Python - MegaNode.getChildren() always returns None #2655

ggpwnkthx opened this issue Oct 24, 2023 · 1 comment

Comments

@ggpwnkthx
Copy link

ggpwnkthx commented Oct 24, 2023

Both of the Python example files don't seem to work completely. Logging in, fetching nodes, getting account details, getting contacts, and even creating a folder works without any issues for me. However, attempting to traverse any nodes does not work. Every node, regardless of if it's the root node, an incoming share, or even if I login to a folder. I can get the node's name, but never any children.

I've also tried a very simplified threaded event listener pattern:

from dotenv import load_dotenv
load_dotenv()

import os
import mega
import threading

class Listener(mega.MegaListener):
    """
    Custom listener for the Mega API, which handles API responses and errors.

    Attributes
    ----------
    event : threading.Event
        An event to signal when our operations are complete.
    root_node : mega.MegaNode
        The root node after fetching nodes from the Mega API.
    results : mega.MegaRequest
        The results from the Mega API request.
    error : str
        Error message, if any error occurs while making a request to the Mega API.

    Methods
    -------
    onRequestFinish(api, request, error):
        Callback function which is executed when the Mega API request is finished.
    """

    def __init__(self):
        """
        Initialize the Listener class with its attributes.
        """
        super().__init__()
        self.event = threading.Event()
        self.root_node = None
        self.results = None
        self.error = None

    def onRequestFinish(self, api, request, error):
        """
        Callback function which is executed when the Mega API request is finished.

        Parameters
        ----------
        api : mega.MegaApi
            The Mega API instance.
        request : mega.MegaRequest
            The Mega API request.
        error : mega.MegaError
            The error, if any, from the Mega API request.
        """
        if error.getErrorCode() != mega.MegaError.API_OK:
            self.error = "Mega API error: " + error.getErrorString()
        else:
            if request.getType() == mega.MegaRequest.TYPE_LOGIN:
                print(request)
                api.fetchNodes()
            elif request.getType() == mega.MegaRequest.TYPE_FETCH_NODES:
                print(request)
                self.root_node = api.getRootNode()
                self.event.set()
            else:
                self.results = request.copy()
                self.event.set()

def main():
    """
    Main function to demonstrate the usage of the Mega API.
    """
    # Create a MegaApi instance with the given application key
    api = mega.MegaApi("YOUR_APP_KEY")

    # Use an event to signal when our operations are complete
    listener = Listener()
    api.addListener(listener)

    # Login to Mega
    api.login(os.getenv("mega_email"), os.getenv("mega_password"))
    listener.event.wait()
    
    # Error handling
    if listener.error != None:
        raise Exception(listener.error)

    # Print the name and children of the root node
    print(listener.root_node.getName())
    print(listener.root_node.getChildren())

    # Remove the listener from the Mega API instance
    api.removeListener(listener)

if __name__ == "__main__":
    main()

Running the above code I get the following output:

vscode ➜ /workspaces/py-mega (main) $ /usr/local/bin/python /workspaces/py-mega/mega/example.py
LOGIN
FETCH_NODES
Cloud Drive
None

Despite there being items in the root:
image

My build script is pretty straight forward.

#! /bin/sh
rm -rf sdk
git clone https://github.com/meganz/sdk.git --branch v4.29.0 --single-branch sdk
cd sdk || exit

autoupdate
./autogen.sh
./configure --disable-silent-rules --disable-examples --enable-python --with-python3 --with-sodium
make -j$(nproc --all)

cd bindings/python/ || exit
python3 setup.py bdist_wheel
cp -f build/lib/mega/* ../../../mega

And it's compiled using a container with the following Dockerfile:

FROM mcr.microsoft.com/devcontainers/python:1-3.11-bullseye

RUN apt-get -qq update 
RUN sudo apt-get -qq install -y --no-install-recommends \
    git g++ gcc autoconf automake m4 libtool make swig \
    libcurl4-openssl-dev libcrypto++-dev libsqlite3-dev libc-ares-dev libsodium-dev \
    libnautilus-extension-dev libssl-dev libfreeimage-dev libboost-all-dev
RUN pip install ipykernel python-dotenv wheel

I have also tried building with Python 3.9, but I get the same results.

@lockermanwxlf
Copy link

lockermanwxlf commented Jan 29, 2024

MegaNode::getChildren() always returns NULL unless used on a node returned MegaApi::authorizeNode according to the Doxygen docs. You would have to use MegaApi::getChildren(), but I don't know if that actually works as I'm on an older version using MegaApi::getFileFolderChildren()

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