Reputation: 95
I have the following script that allows me to upload files to bestream.tv. This does not work for files above the 95MB. What change could make?
import requests
import re
sessionObj = requests.session()
sessionObj.post('http://bestream.tv/login.html', data={'loginUsername':'my_user', 'loginPassword':'my_pass', 'submitme':'1'})
filehandle = open('Diabolik Lovers - 12.mp4', 'rb')
resp = sessionObj.get('http://bestream.tv/account_home.html')
url_form = re.search('url: \'(http:\/\/.*)?\'', resp.text).group(1)
sessionid = re.search('_sessionid:\s\'(.*)?\', cTracker:', resp.text).group(1)
ctracker = re.search('cTracker:\s\'(.*)?\', maxChun', resp.text).group(1)
r = sessionObj.post(url_form, data={'_sessionid':sessionid, 'folderId':'', \
'cTracker':ctracker, 'maxChunkSize':'100000000'}, files={'files[]':(filehandle.name, filehandle)})
print(r.text)
This prints as a result:
413 Request Entity Too Largue
To upload the file from the web, I get these results in chrome -> Network:
Accept:application/json, text/javascript, */*; q=0.01
Content-Disposition:attachment; filename="Diabolik%20Lovers%20-%206.5.mp4"
Content-Range:bytes 0-99999999/168152948
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryHNdI5JvVzIVROkWQ
Origin:http://bestream.tv
Referer:http://bestream.tv/account_home.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
Accept:application/json, text/javascript, */*; q=0.01
Content-Disposition:attachment; filename="Diabolik%20Lovers%20-%206.5.mp4"
Content-Range:bytes 100000000-168152947/168152948
Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryfsXuVqiBMXo1Vtn7
Origin:http://bestream.tv
Referer:http://bestream.tv/account_home.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36
And so on until you finish uploading your file.
So I implied that it is rising every 100000000 bytes. What should I modify my script to do the same?
Upvotes: 3
Views: 7238
Reputation: 7033
The error you are getting is the way of the web server telling you, that you can't, in fact, upload larger files. How big a request the server accepts is up to the server administrator, and not in any way in control of the client (your code).
I assume, because the docs of requests
don't explicitly tell: Posting with maxChunkSize
would allow a "chunked" HTTP transfer (see also: http://en.wikipedia.org/wiki/Chunked_transfer_encoding) which leaves still the file size intact, because the chunking is on another abstraction layer.
I'm afraid you'd have to slice the file yourself and POST each piece.
Upvotes: 3