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

Receiving a traceback on opencv opening images with python?
How to understand closure in a lambda?
Python: Pickle error with SVM usage
How to use conda to install Github package specutils?
Find Multiple Flagged String within String Python
Create a new numpy array with values based on coordinates and external variables
Counting the Number of Frames in a Video file using OpenCV?
How to create 2 actions with same path but different HTTP methods DRF
Inconsistent results using ALS in Apache Spark
Getting high sampling rates in my Matlab experiment
Import from plugins
matplotlib issue with plotting lists
Is it possible to combine VPython and Pygame?
django queryset with higher number of count
How can I add two functions together in Python 3?
Why am i getting WindowsError: [Error 5] Access is denied?

Categories

HOME
ember.js
xamarin.android
textwatcher
facebook-graph-api
codeeffects
rebol
gspread
jpanel
ndis
equalizer
session-timeout
saiku
multicore
embedly
avplayeritem
iup
k2
remove-method
rworldmap
tflearn
ui5
owl-api
fileinfo
forum
pitest
bxslider
websauna
polymorphism
hawtio
nsurlconnection
boilerplate
text-files
tripwire
datalog
cppunit
matlab-cvst
worker
encapsulation
openweathermap
archer
web-deployment-project
multi-agent
xmgrace
component-pascal
pluck
quintus
adler32
createobject
icefaces
children
spatial-query
date-format
acm
self-hosting
getrusage
jenkins-scriptler
ninject.web.mvc
sem
urn
harp
httpie
low-level
pgagent
cocoascript
bsp
coin-flipping
neoload
wss
sgml
late-static-binding
winrt-httpclient
operations
windows-mobile-6
layered
execvp
dynamic-binding
entity-framework-4.1
digital-design
fluidsynth
web-safe-fonts
redirectstandardoutput
coff
gtk2hs
server-error
squeel
pantheios
getresource
requestfactory
openwysiwyg
soft-keyboard

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