Coder Social home page Coder Social logo

yadiskclient's Introduction

YaDiskClient

https://github.com/TyVik/YaDiskClient/actions/workflows/test.yaml/badge.svg?branch=master https://coveralls.io/repos/github/TyVik/YaDiskClient/badge.svg?branch=master

Client for Yandex.Disk based on WebDav.

Install

pip install YaDiskClient

Source code

github

explanatory article

Passwords and tokens

You must use application password, not account password! Details - https://yandex.ru/support/id/authorization/app-passwords.html

Also, you can create OAuth-token for your application. Details - https://yandex.ru/dev/disk/doc/dg/concepts/quickstart.html

Both methods are supported. You should use method set_login or set_token before start.

Using API

from YaDiskClient.YaDiskClient import YaDisk
disk = YaDisk()
disk.set_auth(login, password)

"""
Library also supports token authorization via:
disk.set_token(token)
"""

disk.df() # show used and available space

disk.ls(path) # list of files/folder with attributes
disk.mkdir(path) # create directory

disk.rm(path) # remove file or directory
disk.cp(src, dst) # copy from src to dst
disk.mv(src, dst) # move from src to dst

disk.upload(src, dst) # upload local file src to remote file dst
disk.download(src, dst) # download remote file src to local file dst

disk.publish_doc(path) # return public url
disk.hide_doc(path) # remove public url form Yandex Disk

Tests

For run tests:
  1. Set Yandex username and password in file tests/test_YaDiskClient.py
  2. python -m unittest discover -s tests -t tests

yadiskclient's People

Contributors

ekstrah avatar glader avatar itkinm avatar samoilenkolev avatar tyvik avatar yegorov 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

Watchers

 avatar  avatar  avatar

yadiskclient's Issues

YaDiskClient just doesn't work

Hello everybody and thanx for such a useful lib. It could resolve a very important issue for me, but I can't get why it doesn't work.
So, my way is like that:

from YaDiskClient.YaDiskClient import YaDisk

disk = YaDisk('[email protected]', 'just_pass_for_mail')
disk.publish_doc('/a_document.pdf')

So after that I get this output:

YaDiskException                           Traceback (most recent call last)
<ipython-input-14-657e99db9776> in <module>
      7 
      8 disk = YaDisk('[email protected]', 'just_pass_for_mail')
----> 9 disk.publish_doc('/a_document.pdf')

/usr/local/lib/python3.8/site-packages/YaDiskClient/YaDiskClient.py in publish_doc(self, path)
    218     def publish_doc(self, path):
    219         warn('This method was deprecated in favor method "publish"', DeprecationWarning, stacklevel=2)
--> 220         return self.publish(path)
    221 
    222     def hide_doc(self, path):

/usr/local/lib/python3.8/site-packages/YaDiskClient/YaDiskClient.py in publish(self, path)
    194             return parseContent(resp.content)
    195         else:
--> 196             raise YaDiskException(resp.status_code, resp.content)
    197 
    198     def unpublish(self, path):

YaDiskException: 401. b''

Or, maybe, this project is abandoned and now we should search another way to deal with YaDisk?

memory problem

if u do not change "f.read()" to "f" in upload function, it will give memory exception.
(since requests library supports streaming upload with file-like object)

example monkey patching:
from YaDiskClient import YaDisk

def upload(self, file, path):
with open(file, "rb") as f:
resp = self._sendRequest("PUT", path, data=f)
if resp.status_code != 201:
raise YaDiskException(resp.status_code, resp.content)

YaDisk.upload = upload

Please, specify login and password for Yandex.Disk account

Hello.
at tests/test_yaDisk.py write my login and password,

LOGIN = os.environ.get('login')
PASSWORD = os.environ.get('6asdasd80')

but when I run

root@digmydomain:~/YaDiskClient-master# python -m unittest discover -s tests -t tests
E
======================================================================
ERROR: setUpClass (test_yaDisk.TestYaDisk)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/root/YaDiskClient-master/tests/test_yaDisk.py", line 24, in setUpClass
    cls.disk = YaDisk(LOGIN, PASSWORD)
  File "YaDiskClient/YaDiskClient.py", line 53, in __init__
    raise YaDiskException(400, "Please, specify login and password for Yandex.Disk account.")
YaDiskException: 400. Please, specify login and password for Yandex.Disk account.

----------------------------------------------------------------------
Ran 0 tests in 0.001s

FAILED (errors=1)
root@digmydomain:~/YaDiskClient-master# 

What I doing wrong?

install problem on windows 7

DEPRECATION: --no-install, --no-download, --build, and --no-clean are deprecated. See pypa/pip#906.
Downloading/unpacking YaDiskClient
Downloading YaDiskClient-0.3.tar.gz
Running setup.py (path:C:\Users\berty\AppData\Local\Temp\pycharm-packaging0.tmp\YaDiskClient\setup.py) egg_info for package YaDiskClient
Traceback (most recent call last):
File "", line 17, in
File "C:\Users\berty\AppData\Local\Temp\pycharm-packaging0.tmp\YaDiskClient\setup.py", line 3, in
import YaDiskClient
File "C:\Users\berty\AppData\Local\Temp\pycharm-packaging0.tmp\YaDiskClient\YaDiskClient__init__.py", line 6, in
from YaDiskClient import YaDiskException, YaDisk
ImportError: cannot import name 'YaDiskException'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 17, in

File "C:\Users\berty\AppData\Local\Temp\pycharm-packaging0.tmp\YaDiskClient\setup.py", line 3, in

import YaDiskClient

File "C:\Users\berty\AppData\Local\Temp\pycharm-packaging0.tmp\YaDiskClient\YaDiskClient__init__.py", line 6, in

from YaDiskClient import YaDiskException, YaDisk

ImportError: cannot import name 'YaDiskException'

publish_do does not wotk on windows (python3)

What about Windows ?

https://github.com/TyVik/YaDiskClient/blob/master/YaDiskClient/YaDiskClient.py#L186

      if path[0] != '/':
            raise YaDiskException("Destination path must be absolute")

On windows

os.path.abspath("file.zip")

will return

d:\some\example\file.zip

on windows ia have an error YaDiskException("Destination path must be absolute")
if i translate path to linux style like /d/some/example/file.zip with some replace function
i see an exeption YaDiskClient.YaDiskClient.YaDiskException: 404. b'resource not found'

UnicodeEncodeError when working with heroku

I had a very strange error.

My sketch:

login = os.environ.get('YANDEX_LOGIN', None)
password = os.environ.get('YANDEX_PASSWORD', None)
disk = YaDiskSmart(login, password)
df = disk.df()

I am using login: [email protected]

When calling a method from the local pc:
disk.df()
The method successfully returns information about ya.disk space.

But after deploying the code to heroku, calling the method raises an exception:

UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)

The sketch works successfully if I change the login, for example, to: [email protected]

Error upload zip file

Upload zip file raise next error

UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 479: character maps to

Solution: YaDiskClient - row 155
with open(file, "r") as f:
need change to
with open(file, "rb") as f:

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.