Python, Pydio, Rest and module requests to send a file


Totally newbie on python, I had to try to upload a gzip file using requests module and python3.5 launched from a freeBSD bash.

Here is my after gathering the Internet information I managed to get:

#!/usr/bin/env python3.5
import requests, os.path, sys, glob, time, re, datetime
urlPydio =''
certPydio = 'remote.pydio.server.ssl.crt'
depotDistant = 'ws'
urlComplet = urlPydio + "/api/" + depotDistant + "/"
loginPydio = ''`
passwordPydio = 'PASSWORD'
repLocal = os.path.abspath('/var/squid/logs/access_log_gz/')
yesterday = - datetime.timedelta(days=1)
listFichiers = os.listdir(repLocal)

for fichier in listFichiers:`
    if ('^\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')}
        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)
            print('error sending file ', codeRetour, rest.text)
    except requests.exceptions.RequestException as e:

As a result, I managed to get the log.gz file on remote pydio server but there is some headers stuff added in the file, making it impossible to unzip. Open with a notepad, the 3 lines to remove are :


Content-Disposition: form-data; name="log.gz"; filename="log.gz"

I tried some stuff, unsuccessful, I tried to change headers values to None, no way to send the file. I also tried to rest.prepare() to del headers['Content-Disposition'] unsuccessfully too

rest.headers returns :

{'Content-Type': 'text/html; charset=UTF-8', 'Date': 'Thu, 05 Jan 2017 10:10:16 GMT', 'Transfer-Encoding': 'chunked', 'Set-Cookie': 'AjaXplorer=i6m1ud1cgocokaehc58gelc8m2; path=/; 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'}

Now, I'm here, asking you some help or some papers/posts to read. I just want to upload a log.gz file without any change to the file itself so it can be downloaded and unzipped.

Show source
| rest   | python   | http   | python-requests   | pydio   2017-01-05 15:01 0 Answers

Answers to Python, Pydio, Rest and module requests to send a file ( 0 )

Leave a reply to - Python, Pydio, Rest and module requests to send a file

◀ Go back