Giter VIP home page Giter VIP logo

mega.py's Introduction

This library is no longer maintained, you should instead use the official CLI client MEGAcmd:

Download it: https://mega.io/cmd#downloadapps

Learn how to use it: https://github.com/meganz/MEGAcmd/blob/master/UserGuide.md


Mega.py

Build Status Downloads PyPI version

Python library for the Mega.co.nz API, currently supporting:

  • login
  • uploading
  • downloading
  • deleting
  • searching
  • sharing
  • renaming
  • moving files

This is a work in progress, further functionality coming shortly.

For more detailed information see API_INFO.md

How To Use

Create a Mega account

First, create an account with Mega .

Install mega.py package

Run the following command, or run setup from the latest github source.

pip install mega.py

Import mega.py

from mega import Mega

Create an instance of Mega.py

mega = Mega()

Login to Mega

m = mega.login(email, password)
# login using a temporary anonymous account
m = mega.login()

Get user details

details = m.get_user()

Get account balance (Pro accounts only)

balance = m.get_balance()

Get account disk quota

quota = m.get_quota()

Get account storage space

# specify unit output kilo, mega, gig, else bytes will output
space = m.get_storage_space(kilo=True)

Get account files

files = m.get_files()

Upload a file, and get its public link

file = m.upload('myfile.doc')
m.get_upload_link(file)
# see mega.py for destination and filename options

Export a file or folder

public_exported_web_link = m.export('myfile.doc')
public_exported_web_link = m.export('my_mega_folder/my_sub_folder_to_share')
# e.g. https://mega.nz/#F!WlVl1CbZ!M3wmhwZDENMNUJoBsdzFng

Find a file or folder

folder = m.find('my_mega_folder')
# Excludes results which are in the Trash folder (i.e. deleted)
folder = m.find('my_mega_folder', exclude_deleted=True)

Upload a file to a destination folder

folder = m.find('my_mega_folder')
m.upload('myfile.doc', folder[0])

Download a file from URL or file obj, optionally specify destination folder

file = m.find('myfile.doc')
m.download(file)
m.download_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
m.download(file, '/home/john-smith/Desktop')
# specify optional download filename (download_url() supports this also)
m.download(file, '/home/john-smith/Desktop', 'myfile.zip')

Import a file from URL, optionally specify destination folder

m.import_public_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc')
folder_node = m.find('Documents')[1]
m.import_public_url('https://mega.co.nz/#!utYjgSTQ!OM4U3V5v_W4N5edSo0wolg1D5H0fwSrLD3oLnLuS9pc', dest_node=folder_node)

Create a folder

m.create_folder('new_folder')
m.create_folder('new_folder/sub_folder/subsub_folder')

Returns a dict of folder node name and node_id, e.g.

{
  'new_folder': 'qpFhAYwA',
  'sub_folder': '2pdlmY4Z',
  'subsub_folder': 'GgMFCKLZ'
}

Rename a file or a folder

file = m.find('myfile.doc')
m.rename(file, 'my_file.doc')

Contact Support

For paid priority support contact [email protected].

UK Python Development Agency

mega.py's People

Contributors

carlesso avatar ckornacker avatar gissehel avatar jlejeune avatar midnightrising avatar plutec avatar richardarpanet avatar voussoir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mega.py's Issues

Undecrypted files in shared folder

I try to upload files and generate link:
fold = m.find(foldpath)
m.upload(local_filepath, fold[0])
megalink = m.export(foldpath)
Have working link, but files in folder turn out not decrypted.
Link, created manually working ok.
If try to see this files by logged user - ok.

Public Folder upload not working

`from mega import Mega

mega = Mega()

print('Logging in to MEGA')

m = mega.login()

print('Logged in')

folder_node = '***************************' # This is a public folder so i expect to upload to it without logging in

print(folder_node)

file_node = m.upload('game.txt', folder_node)

print('done')`
How do I solve it?

Feature suggestion

Hey, I love the API but would it be possible to add a progress bar that indicates the upload and download status?
I think it would be a pretty cool feature.

2FA Support

there doesnt seem to be 2FA support. is it possible to add it?

Error with create_folder

When trying to create a folder, I got an error. My stacktrace is below, from my line of code that creates the folder down. The variables STORIES_DIR is "stories", MEGA_SEP is "/", and folder_name was a string of alphabetic characters.

Stacktrace:

m.create_folder(STORIES_DIR + MEGA_SEP + folder_name)
File "/app/.heroku/python/lib/python3.6/site-packages/mega/mega.py", line 884, in create_folder
existing_node_id = self.find_path_descriptor(directory_name)
File "/app/.heroku/python/lib/python3.6/site-packages/mega/mega.py", line 306, in find_path_descriptor
and file[1]['a']['n'] == foldername):
TypeError: string indices must be integers

My Mega account's directory structure looked like this:

stories
   โฎก folder1
   โฎก folder2

Note that folder1 and folder2 actually have different names, made up of alphabetic characters.

error in the module

Unfortunately, the developers abandoned the project, so I hope for other users ...

Hello! If I want to import another public folder to my cloud drive, then I get the following error:

raise RequestError ('Url key missing') File "/python3.8/site-packages/mega/errors.py", line 58, in __init__ code_desc, long_desc = _CODE_TO_DESCRIPTIONS [code] KeyError: 'Url key missing'

The code I'm using:

mega = Mega()
m = mega.login ('', '')
m.import_public_url('https://mega.nz/folder/XEIz0aAK#9IE-2N7XUlWNkcbiDmnWsw')

As far as I understand, this error is in the mega.py module itself, if you know how to fix it, then answer me, the question will always be relevant

Save Login Session

Please How Can I Save my Login in account (Save Session) and reuse it
Thanks!

Download File Error

When Downloading File state-home-water-alok-projects-enclol-work-dir_to_back.info having this issue

('mbpS0SjS', {'h': 'mbpS0SjS', 'p': 'fKwVUDgB', 'u': 'KqPVDPk5RlM', 't': 0, 'a': {'n': 'state-home-water-alok-projects-enclol-work-dir_to_back.info'}, 'k': (3008924797, 1032499355, 1615942575, 308268957), 's': 0, 'ts': 1599594789, 'iv': (1504284862, 1817208414, 0, 0), 'meta_mac': (0, 0), 'key': (3941670083, 1373296325, 1615942575, 308268957, 1504284862, 1817208414, 0, 0)})


Traceback (most recent call last):
  File "enc_beta1.py", line 135, in <module>
    uploadlogic("./dir_to_back")
  File "enc_beta1.py", line 132, in uploadlogic
    update_logic(dic_files, cloud_state_dirname, mega_object)
  File "enc_beta1.py", line 63, in update_logic
    mega_object.download(file_to_get)
  File "/home/water/alok/projects/enclol/lib/python3.8/site-packages/mega/mega.py", line 564, in download
    return self._download_file(file_handle=None,
  File "/home/water/alok/projects/enclol/lib/python3.8/site-packages/mega/mega.py", line 741, in _download_file
    if (file_mac[0] ^ file_mac[1],
IndexError: tuple index out of range

I tried #9 following the fix and using that I was able to get a specific directory file but the file downloaded is of 0 bytes. But I don't why searching for the file and get it didn't work.

Encoding problems with special characters

Hi,
When using mega.py to upload files, I encountered some encoding problems:
Some files with special filename(emoji, special character, etc) will cause unusual phenomenon, the filenames are misinterpreted on MEGA Android client and MEGASync

For example, the โœฆ character will be displayed as &, ๏ผ–๏ผ(full-width number) as garbage characters, and some appear to be BLANK on Android client(decoding failure, I guess)
Furthermore, these files cannot be synced with MEGASync(it just can't see them, I think)

However, these filenames can be displayed normally on MEGA Web; And if uploaded with MEGA official clients, everything is fine
So I'm wondering whether there's something different in encoding between mega.py and official clients, as is stated in the api doc(https://github.com/meganz/sdk/blob/develop/doc/source/internals.rst):

As JSON is not binary clean, all non-ASCII data has to be encoded. For binary data, the MEGA API uses a variation of base-64 with the characters -_ used instead of +/ and the trailing = stripped (where necessary, the actual payload length is heuristically inferred after decoding, e.g. by stripping trailing NULL bytes). Unicode text has to be encoded as UTF-8.

I also found that:

  • In web client, these files can cause filename conflicts with normally uploaded files
  • If you rename the files in web client or copy from one place to another, then it comes back to normal(this process fixes the wrong encoding, I think)
  • These files can be downloaded with correct filename with web client and mega.py

PS: As for version 1.0.8 this issue still exists.

Thanks for your work!

get.files() function limitation

Hi all,
When I use the get.files() function it returns a the files and folders and some useful info about them in json format,
but!
It only returns info about the 3rd 'branch' of the folder tree. After that - there is no data returning about the folders and files that exists in the deeper 'layers'.
for example - the following folder tree:
Cloud Drive:
-Folder1:
--Subfolder1:
---SubSubfolder2:
----File1
---File2
In this example, the get_files() function will return the data about Cloud Drive, Folder1, Subfolder1,
but won't return any data about all the files or folders that under that 3rd 'branch' and further (SubSubfolder2, File1, File2).

Anyone faced that problem too? Any solutions?

How can I open browser?

I would like to login to my mega account and open my cloud drive without having to log in. Is it possible?

Getting errors in mega module

Screenshot_2021-05-09-19-39-07-026_ru iiec pydroid3
Screenshot_2021-05-09-19-38-59-570_ru iiec pydroid3
See in the above images I posted the code sample and output I cant understand what wrong am I doing I installed correct right package mega.py then too errors coming Plz someone help

Chinese decode problem

I used the get_files() method to get all the nodes
But the name of the Chinese file or folder will return unexpected text
For example: I expected to get "ไธญๆ–‡่ณ‡ๆ–™ๅคพ" but I got "รคยธรฆโ€“โ€กรจยณโ€กรฆโ€“โ„ขรฅยคยพ"
Is this a base64 encoding problem? How can this be solved?
Thank you

Mounting the drive

will it be possible to mount a certain folder so that it can be treated as a system disk?
I mean it like a similar function in google-colab drive.mount('/content/gdrive')

Enable logging info

Any option to print logging info to the screen? Would be useful if you want to see the upload progress

I cant login to my account

This is my script
from mega import Mega

mega = Mega()

email= 'My Email '
password = 'My Password'

m = mega.login(email, password)

login using a temporary anonymous account

m = mega.login()

Error here
in _api_request
raise RequestError(int_resp)
mega.errors.RequestError: EACCESS, Access violation (e.g., trying to write to a read-only share)

PermissionError: [Errno 13] Permission denied: 'myfolder'

i get an error when i wanna upload my folder

from mega import Mega
mega = Mega()
m=mega.login("myemail","mypasswd")
m.upload("myfolder"")

that return:

PS C:\Users\Utilisateur\Desktop> python .\megaa.py
Traceback (most recent call last):
  File ".\megaa.py", line 4, in <module>
    m.upload("myfolder")
  File "C:\Python38\lib\site-packages\mega\mega.py", line 757, in upload
    with open(filename, 'rb') as input_file:
PermissionError: [Errno 13] Permission denied: 'myfolder'

Circular import

Hi,
I just tried to use the package and already in import line get fault:

File "T:\4.Projekty\Test\Mega\mega.py", line 2, in
from mega import Mega
ImportError: cannot import name 'Mega' from partially initialized module 'mega' (most likely due to a circular import) (T:\4.Projekty\Test\Mega\mega.py)

Import Public Folder

I want to access a certain file inside a public folder. Is there a method that returns an instance of public folder? I tried to use import_public_url(folder_url) but I get a KeyError: 'Url key missing'.

Rename issue

hi,

thanks for this library!
I wanted to ask what I am doing wrong, or maybe there is some bug:

files = m.get_files()

for file in files:
    file_details = files[file]
    file_name = str(file_details['a']['n'])
    if (file_name.endswith(".mp4")):
        date_time = time.strftime(
            ' %Y-%m-%d', time.localtime(file_details['ts']))
        new_name = str(file_details['ts']) + "_" + file_name
        print(file_details['k'])
        m.rename(file, new_name)

gives me:

(4095499236, 4227643941, 3790350449, 3961640328)
Traceback (most recent call last):
  File "/home/abc/Dev/xyz/MegaVideosRename/main.py", line 22, in <module>
    m.rename(file, new_name)
  File "/home/abc/Dev/xyz/MegaVideosRename/environments/my_env/lib/python3.8/site-packages/mega/mega.py", line 906, in rename
    encrypt_attribs = base64_url_encode(encrypt_attr(attribs, file['k']))
TypeError: string indices must be integers

any idea why ?
looks like under 'k' there are integers..

How to I fix this error?

Traceback (most recent call last):
File "E:/Users/venv/mega.py", line 9, in
k= m.export('test/test2.txt')
File "E:\Users\venv\mega\mega.py", line 588, in export
node_data = self._node_data(node)
File "E:\Users\venv\mega\mega.py", line 397, in _node_data
return node[1]
TypeError: 'NoneType' object is not subscriptable

I try export function
m.export('test/test2.txt')
like dir1/txt_file.txt

However, this error has prevented it from being resolved.

export method returns link with undecrypted files

Hi, When calling the export method i get a link to undecrypted files
1036XXL
I personally think this is because of the copyright popup who you need to accept. I tried solving this issue myself. But couldn't make a lot of progress because of my nonexistent Javascript knowledge. When looking at the page source i saw this function.

    var initCopyrightsDialog = function(nodesToProcess, isEmbed) {

        "use strict";

        if (M.isInvalidUserStatus()) {
            return;
        }

        $.itemExportEmbed = isEmbed;
        $.itemExport = nodesToProcess;

        var openGetLinkDialog = function() {

            var exportLink = new mega.Share.ExportLink({
                'showExportLinkDialog': true,
                'updateUI': true,
                'nodesToProcess': nodesToProcess
            });

            exportLink.getExportLink();
        };

        // If they've already agreed to the copyright warning (cws = copyright warning shown)
        if (fmconfig.cws || folderlink) {
            // Go straight to Get Link dialog
            openGetLinkDialog();
            return false;
        }

        // Cache selector
        var $copyrightDialog = $('.copyrights-dialog');

        // Otherwise show the copyright warning dialog
        M.safeShowDialog('copyrights', function() {

            $.copyrightsDialog = 'copyrights';

            return $copyrightDialog;
        });

        // Init click handler for 'I agree' / 'I disagree' buttons
        $('.default-white-button', $copyrightDialog).rebind('click.acceptAction', function() {

            closeDialog();

            // User disagrees with copyright warning
            if (!$(this).hasClass('cancel')) {
                // User agrees, store flag so they don't see it again
                mega.config.set('cws', 1);

                // Go straight to Get Link dialog
                openGetLinkDialog();
            }
        });

        // Init click handler for 'Close' button
        $('.fm-dialog-close', $copyrightDialog).rebind('click.closeDialog', closeDialog);
    };

which in mega.config sets cws to 1. I wanted to check out what this exactly meant but i could not find any mega class when looking at the full javascript source to check out the implications of this. I decided to take a look with burp and these look like the requests being done when clicking the "Accept" button.

import requests

session = requests.session()

burp0_url = "https://g.api.mega.co.nz:443/wsc/udcofqreCMUJw9iK0TK2Jg?sid=iA3RkBhXcmNDTRObzWszfnBZckoxRDM5QWNzyb09v4argnRxWe0WrvN_pg&sn=Y8_jSESeNe8"
burp0_headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0", "Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Referer": "https://mega.nz/", "Origin": "https://mega.nz", "DNT": "1", "Connection": "close"}
session.post(burp0_url, headers=burp0_headers)

burp1_url = "https://g.api.mega.co.nz:443/cs?id=-1476993095&sid=iA3RkBhXcmNDTRObzWszfnBZckoxRDM5QWNzyb09v4argnRxWe0WrvN_pg&domain=meganz&v=2&lang=en"
burp1_headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0", "Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Referer": "https://mega.nz/", "Content-Type": "text/plain;charset=UTF-8", "Origin": "https://mega.nz", "DNT": "1", "Connection": "close"}
burp1_json=[{"a": "uga", "u": "pYrJ1D39Acs", "ua": "*!fmconfig", "v": 1}]
session.post(burp1_url, headers=burp1_headers, json=burp1_json)

burp2_url = "https://g.api.mega.co.nz:443/wsc/udcofqreCMUJw9iK0TK2Jg?sid=iA3RkBhXcmNDTRObzWszfnBZckoxRDM5QWNzyb09v4argnRxWe0WrvN_pg&sn=Yjq32AsqtMc"
burp2_headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0", "Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Referer": "https://mega.nz/", "Origin": "https://mega.nz", "DNT": "1", "Connection": "close"}
session.post(burp2_url, headers=burp2_headers)

burp3_url = "https://g.api.mega.co.nz:443/cs?id=-1476993096&sid=iA3RkBhXcmNDTRObzWszfnBZckoxRDM5QWNzyb09v4argnRxWe0WrvN_pg&domain=meganz&v=2&lang=en"
burp3_headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0", "Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Referer": "https://mega.nz/", "Content-Type": "text/plain;charset=UTF-8", "Origin": "https://mega.nz", "DNT": "1", "Connection": "close"}
burp3_json=[{"a": "l", "i": "JqNQeaXUJy", "n": "uAxVha5b"}]
session.post(burp3_url, headers=burp3_headers, json=burp3_json)

burp4_url = "https://g.api.mega.co.nz:443/wsc/udcofqreCMUJw9iK0TK2Jg?sid=iA3RkBhXcmNDTRObzWszfnBZckoxRDM5QWNzyb09v4argnRxWe0WrvN_pg&sn=kYcLw7B39aA"
burp4_headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0", "Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Referer": "https://mega.nz/", "Origin": "https://mega.nz", "DNT": "1", "Connection": "close"}
session.post(burp4_url, headers=burp4_headers)

burp5_url = "https://g.api.mega.co.nz:443/cs?id=-1476993097&sid=iA3RkBhXcmNDTRObzWszfnBZckoxRDM5QWNzyb09v4argnRxWe0WrvN_pg&domain=meganz&v=2&lang=en"
burp5_headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0", "Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Referer": "https://mega.nz/", "Content-Type": "text/plain;charset=UTF-8", "Origin": "https://mega.nz", "DNT": "1", "Connection": "close"}
burp5_json=[{"a": "s2", "cr": [["uAxVha5b"], ["uAxVha5b"], [0, 0, "bmJJTPRkNC1tys9XEoNNCg"]], "ha": "G4CHddwgS6l65JYB8YWsTA", "i": "JqNQeaXUJy", "n": "uAxVha5b", "ok": "EESDcAijOu1WkrV9HRO5lg", "s": [{"r": 0, "u": "EXP"}]}, {"*!fmconfig": "ELf0a2Py-cv0KR87o0oDFFJfKH_hXELL28VgNeWwnd08riNeF3uhi9bddJyVEzXCAY9FI7rWLSvM9654O6Uu8p8tC9_SRRw", "a": "up", "i": "JqNQeaXUJy"}]
session.post(burp5_url, headers=burp5_headers, json=burp5_json)

burp6_url = "https://g.api.mega.co.nz:443/cs?id=-1476993098&sid=iA3RkBhXcmNDTRObzWszfnBZckoxRDM5QWNzyb09v4argnRxWe0WrvN_pg&domain=meganz&v=2&lang=en"
burp6_headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0", "Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Referer": "https://mega.nz/", "Content-Type": "text/plain;charset=UTF-8", "Origin": "https://mega.nz", "DNT": "1", "Connection": "close"}
burp6_json=[{"a": "log", "e": 99635}]
session.post(burp6_url, headers=burp6_headers, json=burp6_json)

burp7_url = "https://g.api.mega.co.nz:443/wsc/udcofqreCMUJw9iK0TK2Jg?sid=iA3RkBhXcmNDTRObzWszfnBZckoxRDM5QWNzyb09v4argnRxWe0WrvN_pg&sn=kYcLw7B39aA"
burp7_headers = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0", "Accept": "*/*", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Referer": "https://mega.nz/", "Origin": "https://mega.nz", "DNT": "1", "Connection": "close"}
session.post(burp7_url, headers=burp7_headers)

(Its a dummy account dont worry about the cookies)
But i couldn't make much sense of the api keys since the documentation is no longer available. So i am really hoping you can help me with this.

UnboundLocalError

Hello ! I'm just trying to download a file of 10GB and I get the error:

UnboundLocalError: local variable 'i' referenced before assignment

with just this simple code:


from mega import Mega

mega = Mega()
mega.download_url('https://mega.nz/file/dtIAAA4B#wDsWFiFunaYTvljhVvqeCsvwDF31vHKxv39sOH7s2hg', '/content/')

downloading to bytesio

how can i download into an arbitrary file object?
i would like to download just the contents of the file, and not actually store them on disk, as that's wasteful for a file i will only temporarily inspect in-program.
i cannot seem to supply any file handle to any of the methods because they all expect file paths local to the disk, instead of file objects.

How to logout from script?

Whenever I use the script, the script leaves me signed in, is there any function such as mega.logout()?

How can i see the size of a file before downloading it?

Hello, i am using a raspberry pi for downloading stuff, and it doesn't have enough storage, so i wanted to put a condition on my code that checks if a file is bigger than X so it decides if it should download it or not, but i haven't find how to check the file size before downloading it.
of course i can check the file after it is downloaded, but i really need to do it before.
Thanks for responding.

Slow Download/Upload

When I download or upload something to my MEGA Accounts via the Browser, It's realy fast. But when I download or upload something via this wrapper then it's realy slow often.
With this wrapper: Downloading/Uploading mp4 file, with 140mb, takes hours.
With the browser: Downloading/Uploading the same file takes minutes.

The code I'm using is the following:

mega = Mega()
m = mega.login('foo', r'bar')
folder = m.find('MyFiles')

for dirpath, _, filenames in os.walk(path):
        for file in filenames:
            full_path = os.path.join(dirpath, file)
            size_in_b = os.path.getsize(full_path)
            size_in_mb = size_in_b / (1024 * 1024)

            if size_in_mb > 10:
                print(f'Processando {file}...')
                m.upload(full_path, folder[0])

I'm using the newest version from pypi.

Fast download and upload would be important for my program.
Simply, please, tell me, if the problem is at this wrapper or at the MEGA API itself. Are there something I'm missing?

Thanks,

from mega import Mega - invalid syntax

  1. pip install mega.py
  2. just try 'from mega import Mega' and execute

Get this:

    from mega import Mega
  File "C:\Program Files (x86)\Python27\lib\site-packages\mega\__init__.py", line 1, in <module>
    from .mega import Mega  # noqa
  File "C:\Program Files (x86)\Python27\lib\site-packages\mega\mega.py", line 165
    url = f'{self.schema}://g.api.{self.domain}/cs'
                                                  ^
SyntaxError: invalid syntax

Folder

How do you retrieve the file inside the folder

Upload infinite loop

This code does not return anything, I'm getting infinite loop:

from mega import Mega
mega = Mega()
m = mega.login(email, password)
file = m.upload('myfile.doc')
print(file)

This thing does not work also:

# Upload a file to a destination folder
folder = m.find('my_mega_folder')
m.upload('myfile.doc', folder[0])

It finds the folder but goes into a loop in m.upload('myfile.doc', folder[0]).

I found that uploading works very unstable. Sometimes it uploads quickly, sometimes it takes several minutes to upload 500 kB file on a very good internet connection.

cannot import name 'Mega' from 'mega'

I just created a new Ubuntu 20.4.1 VM on Windows 10 / Hyper-V and I ran pip3 install mega.

When I run from mega import Mega in a Python 3.8.2 interpreter I get ImportError: cannot import name 'Mega' from 'mega' (/home/dowcet/.local/lib/python3.8/site-packages/mega/__init__.py\

I have confirmed that path /home/dowcet/.local/lib/python3.8/site-packages/mega/__init__.py exists, and it contains both __init__.py and mega.py

Ratelimits

Hi!

I loooove your Module, and very very thanks for making it. I wanna use this module in an app of mine, that is in development right now. That app would involve searching and downloading files. So I wanted to know if there are any ratelimits involved. If there are any ratelimits, then I will have to think of any other way, but good work! Would be greatful if u either tell about the ratelimits or link me to the docs or both...

Thank you and good work...

Errors with the import_public_url() Function

Hello,
I'm trying to build an automation to a project of mine - using Mega links of shared files to import the files (and folders) to my account, and to each uploaded foleder/file to create a shared link of my own.

The login function is ok, but when I've tried to use the "import_public_url()" I've encountered a few problems:
The URL parsing function is using the wrong split sign ("!" instead of "#") between the Decryption Key and the Link.
Also "#!" is needed after the "/folder/" or "/file/" part in the link.

I've tried to edit the module but I didn't succeed, so I changed my links format to fit the module and it worked.
Until - I got this error :
image
"
Raise RequestError(int_resp)
mega.errors.RequestError: EACCESS, Access violation (e.g., trying to write to a read-only share)
"
I saw in other forums that this error is because "The original owner of this file needs to log in again to re-create keys" or something like that, but when I do this manually through the web I get no errors and the file/folder is imported easily.
Can someone help me in this one?
Thanks!

Cannot log in

When logging in with my email and password I get this:

Traceback (most recent call last):
  File "mega_test.py", line 3, in <module>
    m = Mega.login("email here", "password here")
  File "/home/lithium/.local/lib/python3.8/site-packages/mega/mega.py", line 46, in login
    self._login_user(email, password)
AttributeError: 'str' object has no attribute '_login_user'

Get stream data

it is possible to know the amount of bytes downloaded, to implement a progress bar

unable to download a file

File "D:\PYTHON\lib\shutil.py", line 827, in move
os.unlink(src)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\Users\comp\AppData\Local\Temp\megapy_3wlw70ao'

Get file name by node

mega = Mega()
m = mega.login(email=".....", password=".....")
data = m.get_files_in_node("....")
for value in data:
print(value)
file = m.find(value)
m.download(file)
The above code works till print(value) after that m.find(value) returns a NoneType object because I'm using the node, not the filename.

Is there any way to get the filename via node? Alternatively, is there a way to know the names of files in a folder?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.