Python のまったくの初心者である私は、リクエストモジュールとfreeBSD bash から起動された python3.5を使用して gzip ファイルをアップロードしようとしなければなりませんでした。
なんとか取得したインターネット情報を収集した後のupload.pyは次のとおりです。
#!/usr/bin/env python3.5
import requests, os.path, sys, glob, time, re, datetime
urlPydio ='https://remote.pydio.server.fr'
certPydio = 'remote.pydio.server.ssl.crt'
depotDistant = 'ws'
urlComplet = urlPydio + "/api/" + depotDistant + "/"
loginPydio = 'user.name'`
passwordPydio = 'PASSWORD'
repLocal = os.path.abspath('/var/squid/logs/access_log_gz/')
yesterday = datetime.date.today() - datetime.timedelta(days=1)
listFichiers = os.listdir(repLocal)
for fichier in listFichiers:`
if re.search ('^\w{5}_\w{4}_\w+_'+ str(yesterday) + '.gz$', fichier):
nomFichierComplet = repLocal +'/'+ fichier
headers = {'x-File-Name': fichier}
urlAction = urlComplet + "upload/input_stream" + "/remote_folder/remote_folder/"
print(nomFichierComplet, urlAction)
files = {fichier: open(nomFichierComplet, 'rb')}
try:
rest = requests.put(urlAction, files=files, auth=(loginPydio,passwordPydio), headers=headers, verify=False)
codeRetour = rest.status_code
if codeRetour == 200:
print('file sent succcessfully', codeRetour, rest.headers)
else:
print('error sending file ', codeRetour, rest.text)
except requests.exceptions.RequestException as e:
print(e)
その結果、リモートのpydioサーバーでlog.gzファイルを取得できましたが、ファイルにいくつかのヘッダーが追加されており、解凍できませんでした。メモ帳で開きます。削除する 3 行は次のとおりです。
--223ef42df08f4792ba6ef6e71cdf749c
Content-Disposition: フォームデータ。名前="log.gz"; ファイル名="log.gz"
request.postのものをいくつか試しましたが、失敗しました。ヘッダーの値をNoneに変更しようとしましたが、ファイルを送信する方法がありません。私もrest.prepare()をdel headers['Content-Disposition']にしようとしましたが失敗しました
rest.headers の戻り値:
{'コンテンツ タイプ': 'text/html; charset=UTF-8', 'Date': 'Thu, 05 Jan 2017 10:10:16 GMT', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'AjaXplorer=i6m1ud1cgocokaehc58gelc8m2; パス=/; HttpOnly', 'Vary': 'Accept-Encoding', 'Connection': 'keep-alive', 'Server': 'nginx', 'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0', 'Content-Encoding': 'gzip', 'Expires': 'Thu, 19 Nov 1981 08:52:00 GMT', 'Pragma': 'no-cache' }
今、私はここにいて、あなたにいくつかの助けやいくつかの論文/投稿を読んでもらいたいと思っています. ダウンロードして解凍できるように、ファイル自体を変更せずに log.gz ファイルをアップロードしたいだけです。