首页 > 解决方案 > 安装的 pyocclient 得到 AttributeError: module 'owncloud' has no attribute 'Client'

问题描述

我正在尝试使用pyocclient包将 owncloud 集成到我的 django 网站中。我使用它安装了它,pip install pyocclient然后我从他们的文档中尝试了这个示例代码,但得到了owncloud没有attr的错误Client

这是我的代码

from django.contrib.auth.decorators import login_required
import owncloud

@login_required
def index(request):
    if request.method == "GET":
        return render(request, 'home.html')
    else:
        f = request.POST['file'] # a txt file
        public_link = 'https://lblostenzexxx.owncloud.online/index.php/x/3'

        oc.login('uid', 'password')
        oc.mkdir('testdir')
        oc.put_file(f, 'localfile.txt')
        link_info = oc.share_file_with_link(f)
        print(link_info.get_link())
        return render(request, 'home.html', {'msg':"return"})

下面是控制台错误:

System check identified no issues (0 silenced).
May 30, 2021 - 03:30:14
Django version 3.1.5, using settings 'owncloud.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
[30/May/2021 03:30:14] "GET / HTTP/1.1" 200 1084
[30/May/2021 03:30:14] "GET /static/css/login_signup.css HTTP/1.1" 200 2813
Internal Server Error: /
Traceback (most recent call last):
  File "C:\Users\mhashirhassan22\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\mhashirhassan22\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\mhashirhassan22\AppData\Local\Programs\Python\Python38-32\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "D:\Work\Others\Upwork\owncloud\owncloud\users\views.py", line 13, in index
    oc = owncloud.Client.from_public_link(public_link)
AttributeError: module 'owncloud' has no attribute 'Client'

这是 pyocclient 的 github 链接https://github.com/owncloud/pyocclient

如果有任何替代方法可以在没有 pyocclient 的情况下在我的 django 网站上上传、共享文件,它也可以帮助我。谢谢!

标签: pythondjangopipowncloud

解决方案


推荐阅读