seafile python api requests

seafile api:


API基础:


所有的API调用必须使用一个正确的Seafile API key


快速开始:


ping 


[root@node01 ~]# curl http://192.168.137.1:8000/api2/ping/
"pong"[root@node01 ~]#




curl https://192.168.137.1/api2/ping/


# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import re
import requests
s=requests.session()
r= s.get('https://192.168.137.1:8000/api2/ping/')
print r.content


requests.exceptions.SSLError: HTTPSConnectionPool(host='192.168.137.1', port=8000): Max retries exceeded with url: /api2/ping/ (Caused by SSLError(SSLError(1, u'[SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)'),))


[root@node01 ~]# curl http://192.168.137.1:8000/api2/ping/
"pong"[root@node01 ~]# 


# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import re
import requests
s=requests.session()
r= s.get('http://192.168.137.1:8000/api2/ping/')
print r.content


C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/seafile/a1.py
"pong"


[root@node01 ~]# curl http://192.168.137.1:8000/api2/ping/
"pong"[root@node01 ~]# 


curl -d "username=username@example.com&password=123456" https://cloud.seafile.com/api2/auth-token/


得到auth token:


curl -d "username=99999@zjtlcb.com&password=1234567" http://192.168.137.1:8000/api2/auth-token/


[root@node01 ~]# curl -d "username=99999@zjtlcb.com&password=1234567" http://192.168.137.1:8000/api2/auth-token/
{"token": "0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7"}[root@node01 ~]# 




       -d/--data <data>
              (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled  in
              an  HTML  form  and  presses  the submit button. This will cause curl to pass the data to the server using the content-type applica-
              tion/x-www-form-urlencoded.  Compare to -F/--form.


              -d/--data is the same as --data-ascii. To post data purely binary, you should instead use the --data-binary  option.  To  URL-encode
              the value of a form field you may use --data-urlencode.


              If  any  of  these options is used more than once on the same command line, the data pieces specified will be merged together with a
              separating  &-symbol.  Thus,  using  ’-d  name=daniel  -d   skill=lousy’   would   generate   a   post   chunk   that   looks   like
              ’name=daniel&skill=lousy’.


              If  you  start  the  data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the
              data from stdin.  The contents of the file must already be URL-encoded. Multiple files can also be specified. Posting  data  from  a
              file named ’foobar’ would thus be done with --data @foobar.






(HTTP) 发送指定的数据在一个POST 请求到HTTP server,这与用户填充一个HTML 表单浏览器所做的方式相同。


填写一个HTML表单,按下submit 按钮。


这个会导致curl 传递数据到server 使用content-type applica-tion/x-www-form-urlencoded


-d/--data 是和 --data-ascii相同。


1.得到auth key
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import re
import requests
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import re
import requests
s=requests.session()
#response = s.get(url, params=datas, **kwargs)
headers = {'Content-Type': 'application/json'}    ## headers中添加上content-type这个参数,指定为json格式
datas={'username': '99999@zjtlcb.com', 'password': '1234567'}
response = s.post('http://192.168.137.1:8000/api2/auth-token/', data=json.dumps(datas),headers=headers)
print response.text


C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/seafile/a2.py
{"token": "0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7"}






auth ping 


curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' http://192.168.137.1:8000/api2/auth/ping/


[root@node01 ~]# curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' http://192.168.137.1:8000/api2/auth/ping/
"pong"[root@node01 ~]# 






def authping():
    a='Token '+token
    print '----------'
    print type(a)
    print '----------'
    headers = {'Content-Type': 'application/json','Authorization':a}  ## headers中添加上content-type这个参数,指定为json格式
    print headers
    response = s.get('http://192.168.137.1:8000/api2/auth/ping/',  headers=headers)
    return response.text
print authping()


C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/seafile/a2.py
{"token": "0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7"}
{"token": "0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7"}
<type 'unicode'>
<type 'dict'>
0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7
----------
<type 'unicode'>
----------
{'Content-Type': 'application/json', 'Authorization': u'Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7'}
"pong"




Account:


列出账户


curl -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/accounts/
[root@node01 ~]# curl -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/accounts/
[
    {
        "source": "DB",
        "email": "015208@zjtlcb.com"
    },
    {
        "source": "DB",
        "email": "99999@zjtlcb.com"
    },
    {
        "source": "DB",
        "email": "zhaoyangjian@gmail.com"
    },
    {
        "source": "DB",
        "email": "zhangzhong@gmail.com"
    },
    {
        "source": "DB",
        "email": "zhouhaiwu@gmail.com"
    }
][root@node01 ~]# 


def  listaccount():
    a = 'Token ' + token
    headers = {'Content-Type': 'application/json', 'Authorization': a}  ## headers中添加上content-type这个参数,指定为json格式
    response = s.get('http://192.168.137.1:8000/api2/accounts/', headers=headers)
    print response.text
print listaccount()


[{"source": "DB", "email": "015208@zjtlcb.com"}, {"source": "DB", "email": "99999@zjtlcb.com"}, {"source": "DB", "email": "zhaoyangjian@gmail.com"}, {"source": "DB", "email": "zhangzhong@gmail.com"}, {"source": "DB", "email": "zhouhaiwu@gmail.com"}]
None


Get Account Info


获取账户信息
curl -v -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/account/info/015208@zjtlcb.com




curl -v -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/accounts/user@mail.com/




[root@node01 ~]# curl   -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/accounts/zhouhaiwu@gmail.com/


{
    "is_staff": false,
    "is_active": true,
    "id": 8,
    "create_time": 1504074608548750,
    "usage": 0,
    "total": -2,
    "email": "zhouhaiwu@gmail.com"

def get_account_info():
    a = 'Token ' + token
    headers = {'Content-Type': 'application/json', 'Authorization': a}  ## headers中添加上content-type这个参数,指定为json格式
    response = s.get('http://192.168.137.1:8000/api2/accounts/zhouhaiwu@gmail.com/', headers=headers)
    print response.text
print get_account_info()




检查账户信息:


curl -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/account/info/


[root@node01 ~]# curl -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/account/info/
{
    "login_id": "",
    "name": "99999",
    "institution": "",
    "department": "",
    "contact_email": "",
    "usage": 354873,
    "total": -2,
    "email": "99999@zjtlcb.com"
}[root@node01 ~]# 




创建用户:
curl -v -X PUT -d "password=1234567" -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" 
-H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/accounts/xiaoxiao@gmail.com/




     -X/--request <command>
              (HTTP) Specifies a custom request method to use when communicating with the HTTP server.  The specified request will be used instead
              of the method otherwise used (which defaults to GET). Read the HTTP 1.1 specification for details  and  explanations.  Common  addi-
              tional HTTP requests include PUT and DELETE, but related technologies like WebDAV offers PROPFIND, COPY, MOVE and more.


              (FTP) Specifies a custom FTP command to use instead of LIST when doing file lists with FTP.


              If this option is used several times, the last one will be used.
 
-X/--request <command>

(HTTP) 指定一个自定求的请求方法来使用当和HTTP server 通讯时。

指定的请求会被使用来代替否则使用默认为GET 

def create_accout():
    a = 'Token ' + token
    headers = {'Content-Type': 'application/json', 'Authorization': a}  ## headers中添加上content-type这个参数,指定为json格式
    datas = { 'password': '1234567'}
    response = s.put('http://192.168.137.1:8000/api2/accounts/lbj@gmail.com/', data=json.dumps(datas),headers=headers)
    return response.text
print  create_accout()


C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled/seafile/a2.py
{"token": "0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7"}
{"token": "0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7"}
<type 'unicode'>
<type 'dict'>
0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7
"success"




更新一个账户:
curl -v -X PUT -d "password=1234567&is_staff=true&storage=1073741824" -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/accounts/lbj@gmail.com/


def update_account():
    a = 'Token ' + token
    headers = {'Content-Type': 'application/json', 'Authorization': a}  ## headers中添加上content-type这个参数,指定为json格式
    datas = {'password': '1234567','is_staff':'true','storage':'1073741824'}
    response = s.put('http://192.168.137.1:8000/api2/accounts/lbj@gmail.com/', data=json.dumps(datas), headers=headers)
    return response.text
print  update_account()




删除一个账户:


curl -v -X DELETE -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/accounts/lbj@gmail.com/


def delete_account():
    a = 'Token ' + token
    headers = {'Content-Type': 'application/json', 'Authorization': a}  ## headers中添加上content-type这个参数,指定为json格式
    datas = {'password': '1234567', 'is_staff': 'true', 'storage': '1073741824'}
    response = s.delete('http://192.168.137.1:8000/api2/accounts/xiaoxiao@gmail.com/',  headers=headers)
    return response.text
print delete_account()




Get Server 信息:


def  get_server_infomation():
    response = s.get('http://192.168.137.1:8000/api2/server-info/')
    return  response.text
print get_server_infomation()




Starred Files:


列出标星文件:


curl -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/starredfiles/




[root@node01 ~]# curl -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/starredfiles/
[
    {
        "file_name": "elku7f51u5740.txt",
        "icon_path": "txt.png",
        "oid": "7501be4b6d0557bd26f8425f35e1cbe959f1189a",
        "mtime_relative": "<time datetime="2017-08-22T12:33:06" is="relative-time" title="Tue, 22 Aug 2017 12:33:06 +0800" >2017-08-22</time>",
        "repo": "0219ecf6-0602-4aa7-b9f2-e678255945e5",
        "org": -1,
        "path": "/elku7f51u5740.txt",
        "size": 83,
        "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5",
        "mtime": 1503376386,
        "dir": false,
        "repo_name": "scan"
    }
][root@node01 ~


curl -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/starredfiles/




def List_starred_files():
    a = 'Token ' + token
    headers = {'Content-Type': 'application/json', 'Authorization': a}  ## headers中添加上content-type这个参数,指定为json格式
    response = s.get('http://192.168.137.1:8000/api2/starredfiles/', headers=headers)
    print response.text
print List_starred_files()




Star A File:


curl -v -d "repo_id=0219ecf6-0602-4aa7-b9f2-e678255945e5&p=/elku7f51u5740.txt" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; charset=utf-8; indent=4' http://192.168.137.1:8000/api2/starredfiles/




curl -v -d "repo_id=0219ecf6-0602-4aa7-b9f2-e678255945e5&p=/elk网址.txt" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; charset=utf-8; indent=4' http://192.168.137.1:8000/api2/starredfiles/






"success"[root@node01 ~]# curl -v -d "repo_id=0219ecf6-0602-4aa7-b9f2-e678255945e5&p=/elk网址.txt" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' 


-H 'Accept: application/jset=utf-8; indent=4' http://192.168.137.1:8000/api2/starredfiles/






def star_file():
    a = 'Token ' + token
    headers = {"Authorization": a, "Accept": "application/json; indent=4",
               "content-type": "application/x-www-form-urlencoded"}  ## headers中添加上content-type这个参数,指定为json格式
    datas = {'repo_id': '0219ecf6-0602-4aa7-b9f2-e678255945e5', 'p': '/elk网址.txt'}
    response = s.post('http://192.168.137.1:8000/api2/starredfiles/', data=datas ,headers=headers)
    return response.content
print '------------------------------------------------------------------------------------------------'
print star_file()






Unstar A File


curl -X DELETE -v  -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; charset=utf-8; indent=4' 'http://192.168.137.1:8000/api2/starredfiles/?repo_id=0219ecf6-0602-4aa7-b9f2-e678255945e5&p=/elk网址.txt'


curl -X DELETE -v  -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; charset=utf-8; indent=4' 'http://192.168.137.1:8000/api2/starredfiles/?repo_id=0219ecf6-0602-4aa7-b9f2-e678255945e5&p=/elk网址.txt'




def unstart_file():
    a = 'Token ' + token
    headers = {"Authorization": a, "Accept": "application/json; indent=4",
               "content-type": "application/x-www-form-urlencoded"}  ## headers中添加上content-type这个参数,指定为json格式
    datas = {'repo_id': '0219ecf6-0602-4aa7-b9f2-e678255945e5', 'p': '/elk网址.txt'}
    response = s.delete('http://192.168.137.1:8000/api2/starredfiles/?repo_id=0219ecf6-0602-4aa7-b9f2-e678255945e5&p=/elk网址.txt', headers=headers)
    return response.content
print unstart_file()




组:


列出组信息:


curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/groups/"


[root@node01 ~]# curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/groups/"
{"replynum": 0, "groups": [{"ctime": 1503317042742500, "creator": "99999@zjtlcb.com", "msgnum": 0, "mtime": 1504075633, "id": 1, "name": "11u4f4fu53cbu96c6u56e2aa"}, {"ctime": 1503317049678500, "creator": "99999@zjtlcb.com", "msgnum": 0, "mtime": 0, "id": 2, "name": "u8fd0u8425u4e2du5fc3"}, {"ctime": 1503317516137500, "creator": "99999@zjtlcb.com", "msgnum": 0, "mtime": 0, "id": 4, "name": "u4f1au8ba1u4e2du5fc3"}, {"ctime": 1504073972289750, "creator": "99999@zjtlcb.com", "msgnum": 0, "mtime": 0, "id": 7, "name": "u6d59u5546u8bc1u5238"}, {"ctime": 1504074123721750, "creator": "99999@zjtlcb.com", "msgnum": 0, "mtime": 0, "id": 8, "name": "u5a31u4e50u4e2du5fc3999"}]}[root@node01 ~]# 


def List_Groups():
    a = 'Token ' + token
    headers = {"Authorization": a, "Accept": "application/json; indent=4",
               "content-type": "application/x-www-form-urlencoded"}  ## headers中添加上content-type这个参数,指定为json格式
    response = s.get(
        'http://192.168.137.1:8000/api2/groups/',
        headers=headers)
    return response.content
print List_Groups()




增加一个group:
curl -X PUT -d "group_name=20180531" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/groups/"


[root@node01 ~]# curl -X PUT -d "group_name=20180531" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/groups/"
{"group_id": 9, "success": true}[root@node01 ~]# 


def add_group():
    a = 'Token ' + token
    headers = {"Authorization": a, "Accept": "application/json; indent=4",
               "content-type": "application/x-www-form-urlencoded"}  ## headers中添加上content-type这个参数,指定为json格式
    datas={'group_name':'123456789'}
    response = s.put(
        'http://192.168.137.1:8000/api2/groups/',data=datas,
        headers=headers)
    return response.text
print add_group()






删除一个组:
curl -X DELETE -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/groups/10/"








def delete_group():
    a = 'Token ' + token
    headers = {"Authorization": a, "Accept": "application/json; indent=4",
               "content-type": "application/x-www-form-urlencoded"}  ## headers中添加上content-type这个参数,指定为json格式
    datas = {'group_name': '123456789'}
    response = s.delete(
        'http://192.168.137.1:8000/api2/groups/9/',
        headers=headers)
    return response.text
print  delete_group()






Rename Group


curl -d "operation=rename&newname=pinkfloyd_lovers" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/groups/1/"




[root@node01 ~]# curl -d "operation=rename&newname=pinkfloyd_lovers" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/groups/1/"
"success"[root@node01 ~]#




def rename_group():
    a = 'Token ' + token
    headers = {"Authorization": a, "Accept": "application/json; indent=4",
               "content-type": "application/x-www-form-urlencoded"}  ## headers中添加上content-type这个参数,指定为json格式
    datas = {'operation': 'rename','newname':'who am i'}
    response = s.post(
        'http://192.168.137.1:8000/api2/groups/4/', data=datas,
        headers=headers)
    return response.text
print rename_group()


Group Member
Add A Group Member




curl -X PUT -d "user_name=aaaa@gmail.com"-H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/groups/1/members/"




<type 'dict'>
0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7
{
    "replynum": 0,
    "groups": [
        {
            "ctime": 1503317042742500,
            "creator": "99999@zjtlcb.com",
            "msgnum": 0,
            "mtime": 1504075633,
            "id": 1,
            "name": "pinkfloyd_lovers"
        },
        {
            "ctime": 1503317049678500,
            "creator": "99999@zjtlcb.com",
            "msgnum": 0,
            "mtime": 0,
            "id": 2,
            "name": "u8fd0u8425u4e2du5fc3"
        },
        {
            "ctime": 1503317516137500,
            "creator": "99999@zjtlcb.com",
            "msgnum": 0,
            "mtime": 0,
            "id": 4,
            "name": "who am i"
        },
        {
            "ctime": 1504073972289750,
            "creator": "99999@zjtlcb.com",
            "msgnum": 0,
            "mtime": 0,
            "id": 7,
            "name": "u6d59u5546u8bc1u5238"
        },
        {
            "ctime": 1504074123721750,
            "creator": "99999@zjtlcb.com",
            "msgnum": 0,
            "mtime": 0,
            "id": 8,
            "name": "u5a31u4e50u4e2du5fc3999"
        }
    ]
}


Get Group Messages


curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/group/msgs/1/"




[root@node01 ~]# 
[root@node01 ~]# curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/group/msgs/1/"
{"next_page": -1, "msgs": [{"reply_cnt": 1, "timestamp": 1504075633, "replies": [{"msg": "u56deu590du4e2du56fdu4f1fu5927--99999", "timestamp": 1504076582, "nickname": "99999", "msgid": 3, "from_email": "99999@zjtlcb.com"}], "from_email": "99999@zjtlcb.com", "msgid": 3, "msg": "u4e2du56fdu4f1fu5927", "nickname": "99999"}, {"reply_cnt": 3, "timestamp": 1504075579, "replies": [{"msg": "reply from scan", "timestamp": 1504076308, "nickname": "015208", "msgid": 1, "from_email": "015208@zjtlcb.com"}, {"msg": "u56deu590du4e2du56fdu4f1fu5927--99999", "timestamp": 1504076501, "nickname": "99999", "msgid": 2, "from_email": "99999@zjtlcb.com"}, {"msg": "u56deu590du4e2du56fdu4f1fu5927--99999", "timestamp": 1504076653, "nickname": "015208", "msgid": 4, "from_email": "015208@zjtlcb.com"}], "from_email": "99999@zjtlcb.com", "msgid": 2, "msg": "20170830u6d4bu8bd5u6d88u606fabcdefg", "nickname": "99999"}, {"reply_cnt": 0, "timestamp": 1503320928, "replies": [], "from_email": "99999@zjtlcb.com", "msgid": 1, "msg": "message||dhAJDHjd", "nickname": "99999"}]}[root@node01 ~]# 


def  get_group_message():
   token = gettoken()
   a = 'Token ' + token
   headers = {"Authorization": a}  ## headers中添加上content-type这个参数,指定为json格式
   response = s.get(
    'http://192.168.137.1:8000/api2/group/msgs/1/',
   headers=headers)
   return response.text
print get_group_message()


Get Group Message Detail:


curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7'  'http://192.168.137.1:8000/api2/group/msgs/1/'


[root@node01 ~]# curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7'  'http://192.168.137.1:8000/api2/group/msgs/1/'
{"next_page": -1, "msgs": [{"reply_cnt": 1, "timestamp": 1504075633, "replies": [{"msg": "u56deu590du4e2du56fdu4f1fu5927--99999", "timestamp": 1504076582, "nickname": "99999", "msgid": 3, "from_email": "99999@zjtlcb.com"}], "from_email": "99999@zjtlcb.com", "msgid": 3, "msg": "u4e2du56fdu4f1fu5927", "nickname": "99999"}, {"reply_cnt": 3, "timestamp": 1504075579, "replies": [{"msg": "reply from scan", "timestamp": 1504076308, "nickname": "015208", "msgid": 1, "from_email": "015208@zjtlcb.com"}, {"msg": "u56deu590du4e2du56fdu4f1fu5927--99999", "timestamp": 1504076501, "nickname": "99999", "msgid": 2, "from_email": "99999@zjtlcb.com"}, {"msg": "u56deu590du4e2du56fdu4f1fu5927--99999", "timestamp": 1504076653, "nickname": "015208", "msgid": 4, "from_email": "015208@zjtlcb.com"}], "from_email": "99999@zjtlcb.com", "msgid": 2, "msg": "20170830u6d4bu8bd5u6d88u606fabcdefg", "nickname": "99999"}, {"reply_cnt": 0, "timestamp": 1503320928, "replies": [], "from_email": "99999@zjtlcb.com", "msgid": 1, "msg": "message||dhAJDHjd", "nickname": "99999"}]}[root@node01 ~]# 




def get_group_message_detail():
    token = gettoken()
    a = 'Token ' + token
    headers = {"Authorization": a}  ## headers中添加上content-type这个参数,指定为json格式
    response = s.get(
        'http://192.168.137.1:8000/api2/group/1/msg/1/',
        headers=headers)
    return response.text
print get_group_message_detail()




Send A Group Message


curl -d "message=20180531 测试" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/group/msgs/1/"


[root@node01 ~]# curl -d "message=20180531 测试 再次测试" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/group/msgs/4/"
{"msgid": 8}[root@node01 ~]# 




共享文件:
curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/shared-links/"


List File Share Links
[root@node01 ~]# curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/shared-links/"
{"fileshares": [{"username": "99999@zjtlcb.com", "repo_id": "faf2516c-a35e-4d8d-9520-0a3da4dbc503", "ctime": null, "s_type": "d", "token": "358c371b01", "view_cnt": 0, "path": "/"}, {"username": "99999@zjtlcb.com", "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "ctime": null, "s_type": "d", "token": "b1cd97a948", "view_cnt": 0, "path": "/"}, {"username": "99999@zjtlcb.com", "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "ctime": null, "s_type": "f", "token": "df0da1bded", "view_cnt": 0, "path": "/elku7f51u5740.txt"}]}[root@node01 ~]# 




def list_file_share_links():
    # token = gettoken()
    a = 'Token ' + token
    headers = {"Authorization": a}  ## headers中添加上content-type这个参数,指定为json格式
    response = s.get(
        'http://192.168.137.1:8000/api2/shared-links/',
        headers=headers)
    return response.content
print list_file_share_links()




{"fileshares": [{"username": "99999@zjtlcb.com", "repo_id": "faf2516c-a35e-4d8d-9520-0a3da4dbc503", "ctime": null, "s_type": "d", "token": "358c371b01", "view_cnt": 0, "path": "/"}, {"username": "99999@zjtlcb.com", "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "ctime": null, "s_type": "d", "token": "b1cd97a948", "view_cnt": 0, "path": "/"}, {"username": "99999@zjtlcb.com", "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "ctime": null, "s_type": "f", "token": "df0da1bded", "view_cnt": 0, "path": "/elku7f51u5740.txt"}]}


Create File Share Link:


创建文件共享连接:


curl -v  -X PUT -d "p=/foo.md" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; indent=4' 


https://cloud.seafile.com/api2/repos/afc3b694-7d4c-4b8a-86a4-89c9f3261b12/file/shared-link/






0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7
[{"file_name": "perl u5b89u88c5svn.txt", "icon_path": "txt.png", "oid": "c03e8a7c14d8d2a17aaea6f4d8ca09948bbd5ca4", 


"mtime_relative": "<time datetime="2017-08-30T11:16:03" is="relative-time" title="Wed, 30 Aug 2017 11:16:03 +0800" >2017-08-30</time>",


 "repo": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "org": -1, "path": "/perl u5b89u88c5svn.txt", "size": 1282, 
 
 "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "mtime": 1504062963, "dir": false, "repo_name": "scan"},


 {"file_name": "1.txt", "icon_path": "txt.png", "oid": "0483c45f390c948f4efdf3c788c6e367493ac44a", "mtime_relative":


 "<time datetime="2017-08-30T11:15:54" is="relative-time" title="Wed, 30 Aug 2017 11:15:54 +0800" >2017-08-30</time>", 
 "repo": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "org": -1, "path": "/1.txt", "size": 1739, "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5",
 "mtime": 1504062954, "dir": false, "repo_name": "scan"}, {"file_name": "elku7f51u5740.txt", "icon_path": "txt.png",
 "oid": "7501be4b6d0557bd26f8425f35e1cbe959f1189a", "mtime_relative": "<time datetime="2017-08-22T12:33:06" is="relative-time" title="Tue, 22 Aug 2017 12:33:06 +0800" >2017-08-22</time>",
 "repo": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "org": -1, "path": "/elku7f51u5740.txt", "size": 83, 
 "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "mtime": 1503376386, "dir": false, "repo_name": "scan"}]
None


Create download link for file:


curl -v  -X PUT -d "p=/1.txt" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/a0219ecf6-0602-4aa7-b9f2-e678255945e5/file/shared-link/


[root@node01 ~]# curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/shared-links/"
{"fileshares": [{"username": "99999@zjtlcb.com", "repo_id": "faf2516c-a35e-4d8d-9520-0a3da4dbc503", "ctime": null, "s_type": "d", "token": "358c371b01", "view_cnt": 0, "path": "/"}, {"username": "99999@zjtlcb.com", "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "ctime": null, "s_type": "d", "token": "b1cd97a948", "view_cnt": 0, "path": "/"}, {"username": "99999@zjtlcb.com", "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "ctime": null, "s_type": "f", "token": "df0da1bded", "view_cnt": 0, "path": "/elku7f51u5740.txt"}]}[root@node01 ~]# 




curl -v  -X PUT -d "p=/1.txt" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/0219ecf6-0602-4aa7-b9f2-e678255945e5/file/shared-link/


[root@node01 ~]# curl   -X PUT -d "p=/1.txt" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/0219ecf6-0602-4aa7-b9f2-e678255945e5/file/shared-link/


{"fileshares": [{"username": "99999@zjtlcb.com", "repo_id": "faf2516c-a35e-4d8d-9520-0a3da4dbc503", "ctime": null, "s_type": "d", "token": "358c371b01", "view_cnt": 0, "path": "/"}, {"username": "99999@zjtlcb.com", "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "ctime": null, "s_type": "d", "token": "b1cd97a948", "view_cnt": 0, "path": "/"},


 {"username": "99999@zjtlcb.com", "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "ctime": null, "s_type": "f", "token": "df0da1bded", "view_cnt": 0, "path": "/elku7f51u5740.txt"}, {"username": "99999@zjtlcb.com", "repo_id": "0219ecf6-0602-4aa7-b9f2-e678255945e5", "ctime": null, "s_type": "f", "token": "359cc746ad", "view_cnt": 0, "path": "/1.txt"}]}
 
Create download link for directory with password and expire date:


curl -v  -X PUT -d "password=password&expire=6&p=/123/" -H 'Authorization: Token f2210dacd9c6ccb8133606d94ff8e61d99b477fd' -H 'Accept: application/json; indent=4' https://cloud.seafile.com/api2/repos/0219ecf6-0602-4aa7-b9f2-e678255945e5/file/shared-link/


Create download link for directory with password and expire date:


0219ecf6-0602-4aa7-b9f2-e678255945e5


curl -v  -X PUT -d "password=987654321&expire=6&p=/scan/" -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/0219ecf6-0602-4aa7-b9f2-e678255945e5/file/shared-link/




Library:


Get Default Library


curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/default-repo/"


[root@node01 ~]# curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/default-repo/"
{"repo_id": "64b9253b-ee5f-4aea-b02a-a6bb8f7f3e52", "exists": true}[root@node01 ~]# 


def get_default_library():
    a = 'Token ' + token
    headers = {"Authorization": a}  ## headers中添加上content-type这个参数,指定为json格式
    datas = {'p': 'perl 安装svn.txt'}
    response = s.get(
        'http://192.168.137.1:8000/api2/default-repo/',
        headers=headers)
    return response.content
print get_default_library()


Create Default Library


curl -X POST -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/default-repo/"


[root@node01 ~]# curl -X POST -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' "http://192.168.137.1:8000/api2/default-repo/"
{"repo_id": "15bb0a00-c61d-4a8f-994e-9e6ba35b34cd", "exists": true}[root@node01 ~]# 


List Libraries:


列出目录


curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/


[root@node01 ~]# curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/ 
[{"permission": "rw", "encrypted": false, "mtime_relative": "<time datetime="2018-05-31T20:24:46" is="relative-time" title="Thu, 31 May 2018 20:24:46 +0800" >13 hours ago</time>", "mtime": 1527769486, "owner": "99999@zjtlcb.com", "root": "7eda5a78f170d5f46e912a445ed92ac5f092eda5", "id": "89eaedee-f113-40a8-827a-421c80667af9", "size": 300544, "name": "My Library", "type": "repo", "virtual": false, "desc": "My Library", "size_formatted": "293.5 KB"}][root@node01 ~]# 
[root@node01 ~]# 


[root@node01 ~]# curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/ 
[{"permission": "rw", "encrypted": false, "mtime_relative": "<time datetime="2018-06-01T10:24:39" is="relative-time" title="Fri, 1 Jun 2018 10:24:39 +0800" >39 seconds ago</time>", "mtime": 1527819879, "owner": "99999@zjtlcb.com", "root": "0000000000000000000000000000000000000000", "id": "d142f360-7b97-437c-af43-e3a416f3a3db", "size": 0, "name": "alipay", "type": "repo", "virtual": false, "desc": "", "size_formatted": "0 bytes"}, 


{"permission": "rw", "encrypted": false, "mtime_relative": "<time datetime="2018-05-31T20:24:46" is="relative-time" title="Thu, 31 May 2018 20:24:46 +0800" >14 hours ago</time>", "mtime": 1527769486, "owner": "99999@zjtlcb.com", "root": "7eda5a78f170d5f46e912a445ed92ac5f092eda5", "id": "89eaedee-f113-40a8-827a-421c80667af9", "size": 300544, "name": "My Library", "type": "repo", "virtual": false, "desc": "My Library", "size_formatted": "293.5 KB"}][root@node01 ~]# 




def list_libraries():
    a = 'Token ' + token
    headers = {"Authorization": a}  ## headers中添加上content-type这个参数,指定为json格式
    #datas = {'p': 'perl 安装svn.txt'}
    response = s.get(
        'http://192.168.137.1:8000/api2/repos/',
        headers=headers)
    return response.content
print list_libraries()


[{"permission": "rw", "encrypted": false, "mtime_relative": "<time datetime="2018-06-01T10:24:39" is="relative-time" title="Fri, 1 Jun 2018 10:24:39 +0800" >4 minutes ago</time>", "mtime": 1527819879, "owner": "99999@zjtlcb.com", "root": "0000000000000000000000000000000000000000", "id": "d142f360-7b97-437c-af43-e3a416f3a3db", "size": 0, "name": "alipay", "type": "repo", "virtual": false, "desc": "", "size_formatted": "0 bytes"},
 {"permission": "rw", "encrypted": false, "mtime_relative": "<time datetime="2018-05-31T20:24:46" is="relative-time" title="Thu, 31 May 2018 20:24:46 +0800" >14 hours ago</time>", "mtime": 1527769486, "owner": "99999@zjtlcb.com", "root": "7eda5a78f170d5f46e912a445ed92ac5f092eda5", "id": "89eaedee-f113-40a8-827a-421c80667af9", "size": 300544, "name": "My Library", "type": "repo", "virtual": false, "desc": "My Library", "size_formatted": "293.5 KB"}]


 
 
 获取我能访问的所有的库:
 
 curl -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/




Sample request for get my owned libraries


得到我们的libraries:


curl -H "Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7" -H 'Accept: application/json; indent=4' "http://192.168.137.1:8000/api2/repos/?type=mine"


[{"permission": "rw", "encrypted": false, "mtime_relative": "<time datetime="2018-06-01T10:24:39" is="relative-time" title="Fri, 1 Jun 2018 10:24:39 +0800" >8 minutes ago</time>", "mtime": 1527819879, "owner": "99999@zjtlcb.com", "root": "0000000000000000000000000000000000000000", "id": "d142f360-7b97-437c-af43-e3a416f3a3db", "size": 0, "name": "alipay", "type": "repo", "virtual": false, "desc": "", "size_formatted": "0 bytes"}, 


{"permission": "rw", "encrypted": false, "mtime_relative": "<time datetime="2018-05-31T20:24:46" is="relative-time" title="Thu, 31 May 2018 20:24:46 +0800" >14 hours ago</time>", "mtime": 1527769486, "owner": "99999@zjtlcb.com", "root": "7eda5a78f170d5f46e912a445ed92ac5f092eda5", "id": "89eaedee-f113-40a8-827a-421c80667af9", "size": 300544, "name": "My Library", "type": "repo", "virtual": false, "desc": "My Library", "size_formatted": "293.5 KB"}]




Get Library Info:


curl -G -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/d142f360-7b97-437c-af43-e3a416f3a3db/


[root@node01 ~]# curl -G -H 'Authorization: Token 0ac9e8585ef6ae51eb62c785d10a6c5102de3ff7' -H 'Accept: application/json; indent=4' http://192.168.137.1:8000/api2/repos/d142f360-7b97-437c-af43-e3a416f3a3db/
{
    "name": "alipay",
    "mtime": 1527819879,
    "owner": "self",
    "encrypted": false,
    "permission": "rw",
    "size": 0,
    "type": "repo",
    "id": "d142f360-7b97-437c-af43-e3a416f3a3db",
    "root": "0000000000000000000000000000000000000000",
    "desc": ""
}[root@node01 ~]# 


 -G/--get
              When  used, this option will make all data specified with -d/--data or --data-binary to be used in a HTTP GET request instead of the
              POST request that otherwise would be used. The data will be appended to the URL with a ’?’ separator.


              If used in combination with -I, the POST data will instead be appended to the URL with a HEAD request.


              If this option is used several times, the following occurrences make no difference. This is  because  undoing  a  GET  doesn’t  make
              sense, but you should then instead enforce the alternative method you prefer.


当被使用时,这个选项会让所有的数据使用 -d/--data 或者  --data-binary 


用于一个HTTP GET 请求代替POST 请求 
def get_library_info():
    a = 'Token ' + token
    headers = {"Authorization": a, "Accept": "application/json; indent=4"}  ## headers中添加上content-type这个参数,指定为json格式
    # datas = {'p': 'perl 安装svn.txt'}
    response = s.get(
        'http://192.168.137.1:8000/api2/repos/d142f360-7b97-437c-af43-e3a416f3a3db/',
        headers=headers)
    return response.content
print get_library_info()








 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 





原文地址:https://www.cnblogs.com/hzcya1995/p/13349189.html