[python-uk] File upload with 'requests' package

Florian BERBAR florian.berbar at urssaf.fr
Mon Dec 5 03:25:13 EST 2016


No i'm not uploading to S3. I upload to a common PHP script. But after i 
analyse a network traffic dump of upload process with Curl, it seams that 
Curl implement  "100 Continue" on my upload, I can read the HTTP header 
"Expect : 100-continue" on the POST request.

I continue my investigation. I will try the chunk implementation as 
"Alistair Broomhead" suggest.

Thank you

Florian


De :    Peter Flood <info at whywouldwe.com>
A :     python-uk at python.org, 
Date :  02/12/2016 18:38
Objet : Re: [python-uk] File upload with 'requests' package
Envoyé par :    "python-uk" 
<python-uk-bounces+florian.berbar=urssaf.fr at python.org>



Are you uploading to S3? 100 Continue is pretty obscure, it's sent by the 
server _before_ the client has sent the body, lots of clients don't expect 
that and handle it badly. See https://github.com/boto/boto/issues/2207

On 02/12/2016 16:10, Florian BERBAR wrote:
Good evening everyone,

I try to post a file (100MB) on a Web form with python3 and the 'requests' 
package. 

This is my implementation : 

--------------------------------------BOF------------------------------------------------- 


#!/usr/local/bin/python3 -u
 
import requests
 
email="user at srv.fr"
 
try:
   res = requests.post('http://server/Upload/upload.php',
                       files={'aFile': open('/tmp/test.zip','rb')},
                       data={'email': email, 'submitFile': 'Envoyer le 
fichier'})
 
except requests.exceptions.Timeout:
   print('timeout')
 
print(res.content)

--------------------------------------EOF-------------------------------------------------

This code semas to be correct, but it return a ConnectionResetError: 
[Errno 104] Connection reset by peer 

The same upload with curl work perfectly with this command : 

curl --form aFile=@"/tmp/test.zip" --form email="user at srv.fr" --form 
submitFile="Envoyer le fichier" http://server/Upload/upload.php 

Thanks to the advance 

Florian 

_______________________________________________
python-uk mailing list
python-uk at python.org
https://mail.python.org/mailman/listinfo/python-uk

_______________________________________________
python-uk mailing list
python-uk at python.org
https://mail.python.org/mailman/listinfo/python-uk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-uk/attachments/20161205/4cc63f37/attachment.html>


More information about the python-uk mailing list