python 模擬創(chuàng)建seafile 目錄操作示例
本文實(shí)例講述了python 模擬創(chuàng)建seafile 目錄操作。分享給大家供大家參考,具體如下:
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import urllib
import cookielib
import json
import httplib
import re
import requests
import StringIO
import time
import sys
import json
import re
s = requests.session()
username='015208@zjtlcb.com'
password='newja01'
myurl='http://10.4.48.2:8000/accounts/login?next=/'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0'
}
response = s.get(myurl, headers=headers,timeout=10)
a= response.content
#<form action="" method="post" class="con"><input type='hidden' name='csrfmiddlewaretoken' value='ZWnUDf5XVX0kagjIoJLKyU8UdO8KBGFn' />
#p=re.compile('.*?<token>(.*?)</token>*')
p=re.compile('.*<form.*value=\'(.*?)\'.*\s+/>',flags=re.S)
m=p.match(a)
print m
token= m.group(1)
print token
myurl='http://10.4.48.2:8000/accounts/login/?next=/'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0'
}
data={'csrfmiddlewaretoken':token,'login':username,'password':password,'next':'/'}
response = s.post(myurl, data=data, headers=headers,timeout=10)
print response.content
u1='http://10.4.48.2:8000/api2/repos/?type=mine&_=1553493865054'
a= s.get(u1).content
print a
print type(a)
b=json.loads(a)
print b
print type(b)
for i in range(len(b)):
print str(b[i]).decode('unicode-escape')
##創(chuàng)建目錄
u2='http://10.4.48.2:8000/api2/repos/?from=web'
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0',
'X-CSRFToken':token,
'Content-Type':'application/json;charset=utf-8'
}
data={"name":"perl","encrypted":"false","passwd1":"","passwd2":"","passwd":"","id":"null","desc":"","mtime"
:0,"mtime_relative":"","owner":"-","owner_nickname":"-"}
response = s.post(u2, data=json.dumps(data), headers=headers,timeout=10)
print response.content
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python文本文件操作技巧匯總》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程》
希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。
- 如何基于Python創(chuàng)建目錄文件夾
- Python腳本按照當(dāng)前日期創(chuàng)建多級(jí)目錄
- 解決python os.mkdir創(chuàng)建目錄失敗的問題
- Python實(shí)現(xiàn)按當(dāng)前日期(年、月、日)創(chuàng)建多級(jí)目錄的方法
- 用Python刪除本地目錄下某一時(shí)間點(diǎn)之前創(chuàng)建的所有文件的實(shí)例
- python實(shí)現(xiàn)一次創(chuàng)建多級(jí)目錄的方法
- python創(chuàng)建和刪除目錄的方法
- Python創(chuàng)建系統(tǒng)目錄的方法
- python判定文件目錄是否存在及創(chuàng)建多層目錄
相關(guān)文章
Python將HTML快速轉(zhuǎn)換成PDF的方法實(shí)現(xiàn)
在Web開發(fā)和報(bào)告任務(wù)中,將HTML內(nèi)容轉(zhuǎn)換為PDF是一種常見需求,本文主要介紹了Python將HTML快速轉(zhuǎn)換成PDF的方法實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
Python3內(nèi)置模塊pprint讓打印比print更美觀詳解
這篇文章主要給大家介紹了關(guān)于Python3內(nèi)置模塊pprint讓打印比print更美觀的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用Python3具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
Python列表list操作相關(guān)知識(shí)小結(jié)
今天,本喵帶大家仔細(xì)溫習(xí)一下Python的列表,溫故而知新,不亦說乎,需要的朋友可以參考下2020-01-01
如何利用Python快速統(tǒng)計(jì)文本的行數(shù)
這篇文章主要介紹了如何利用Python快速統(tǒng)計(jì)文本的行數(shù),要快速統(tǒng)計(jì)一個(gè)文本文件中的行數(shù),其實(shí)就是要統(tǒng)計(jì)這個(gè)文本文件中換行符的個(gè)數(shù),下面我們就一起進(jìn)入文章看看具體的操作過程吧2021-12-12
Python數(shù)據(jù)分析:手把手教你用Pandas生成可視化圖表的教程
今天小編就為大家分享一篇Python數(shù)據(jù)分析:手把手教你用Pandas生成可視化圖表的教程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-12-12

