python


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


A server receives a file succesfuly if it's small enough. Otherwise, it returns an error of "Request Entity Too Large Error 413". This is not a mine server, so I'm unable to deal with it directly.
I'm pretty sure it depends of Content-Length http header (in fact, this is https connection if it 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 I try to send file chunk by chunk for a big file (too big)
chunk_size = 1024
while True:
try:
chunk = f.read(chunk_size)
if not chunk:
break
conn.send(chunk)
except Exception as e:
break
it failed, while on the small files it worked well.
If I manually make Content-Type smaller, it seems(!) to work, at least the error of "Request Entity Too Large Error 413" from a server disappers. But it doesn't work completely because, probably, the format of a file (that's an audio file) becomes broken this way and the server simply is unable to proccess this file by saying that ("wrong format of a file"):
fake_total_size = 1024*10 # it's smaller than a real file size for 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 am I doing wrong and how to solve it?
I guess it has to deal with reading and sending big files by some portions of acceptable size with correct Content-Length value? Or streaming uploading, perhaps?

Related Links

Astroquery SIMBAD : Obtaining data for diameter, mass, distance, luminosity and age of celestial object
Python- Module not having defined attribute
difference between two regular expressions: [abc]+ and ([abc])+
Model does not create a verion after deleting a foreign key model object (django-reversion)
How do I save the entire workspace in pandas (like RData)
Python: Read the content of a variable [duplicate]
How to use timeit for multiple values
Create tab separated print output from a list of tuples python
Print from keyword to end of sequence when sequence is multiple lines
select() on socket and another event mechanism
I try to create a GUI in python to read a file and write a new file but the syntax error shows up
URL common name matching - Python
Odd digit count python
how to post in facebook group that's im member on it using facebook-sdk python
How to chunk up an interval in Python?
How to merge multiple dictionaries

Categories

HOME
vue.js
payment-gateway
jsviews
uibutton
fparsec
cpu-architecture
vs-team-services
memory-leaks
cocos2d-x-3.0
h2
jrebel
histogrammar
ng-admin
android-viewpager
criteria
cpanel
symfony-forms
lenskit
netezza
phpbb
redux-observable
flexlm
mousewheel
cython
distance
marathon
non-deterministic
data-cleansing
pipelinedb
onesignal
xilinx-ise
reply
superagent
stocks
geopy
sonarqube-scan
socketscan
xbim
stereo-3d
matlab-cvst
facebook-chatbot
startapp
double-buffering
ideone
persistent
mbaas
tcserver
castle-dynamicproxy
rxvt
restivejs
libtiff.net
windows-azure-pack
picasa
json-schema-validator
mongo-c-driver
asynccallback
aerogear
qt-linguist
handlebars.java
license-key
lemoon
registrykey
qbfc
pyopengl
epl
lexicographic
iostream
sid
yahoo-boss-api
codeigniter-a3m
internal
roxygen
fogbugz-api
execvp
stagefright
threadx
argb
lame
appfog
fluidsynth
trailing-slash
icsharpcode
bulbs
socketstream
plone-funnelweb
point-sprites
driving-directions
mysql-error-1045
nsindexpath
galaxy-tab
curljs
goliath
gethashcode
audiostreamer
drawtext
graniteds
openvg
webrat
ajaxpro

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App