3

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

7 Comments

So I was looking at the code of the web and network behavior when uploading, the file is uploaded into pieces of what is defined 'maxChunkSize' '100000000'. How could I do to send the file into pieces?
I updated my answer. You probably mistook maxChunkSize for something it isn't.
I updated my question. I read the link you sent me, but I'm more lost than before, I do not know how to direct my problem.
Slice your file in pieces not bigger than what the web server accepts. Upload each one.
How do I can do, so that in the end an all pieces on the server?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.