python - Incorrect Content-Length for a file (Request Entity Too Large 413) -


a server receives file succesfuly if it's small enough. otherwise, returns error of "request entity large error 413". not mine server, i'm unable deal directly.

i'm pretty sure depends of content-length http header (in fact, https connection if matters).

conn = httplib.httpsconnection("www.site.com") conn.connect() conn.putrequest("post", path) conn.putheader("content-type", "some type") conn.putheader("content-length", str(os.path.getsize(file_name))) conn.endheaders() 

even if try send file chunk chunk big file (too big)

chunk_size = 1024  while true:   try:     chunk = f.read(chunk_size)     if not chunk:       break     conn.send(chunk)   except exception e:     break 

it failed, while on small files worked well.

if manually make content-type smaller, seems(!) work, @ least error of "request entity large error 413" server disappers. doesn't work because, probably, format of file (that's audio file) becomes broken way , server unable proccess file saying ("wrong format of file"):

  fake_total_size = 1024*10 # it's smaller real file size sure   conn.putheader("content-length", str(fake_total_size))   f = open(file_name)   chunk_size = fake_total_size   chunk = f.read(chunk_size)   conn.send(chunk) 

what doing wrong , how solve it?

i guess has deal reading , sending big files portions of acceptable size correct content-length value? or streaming uploading, perhaps?


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -