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

Combining different names in a database
Insert into mysql python - not working
How to specify conda requirement file?
Pip installs old version of package
Python Tkinter coordinate canvas error
How can I implement vice versa mapping in Python?
url doesn't change when moving to the next page
Display PiCamera video to an embedded video player in a python program
Parsing CSV from XML document
How to send authenticated email using Python?
Tensorflow: feeding placeholder in loop within loop fails
Get the mean of each column of data between multiple lists
matplotlib uneven group size bar charts side-by-side
Trouble setting up selenium with python3(linux)
Python : ask the number of common word you want
Azure Cognitive text analytics Tool returns 400 Bad request Python

Categories

HOME
plsql
admin-on-rest
payment-gateway
cpu-architecture
jbehave
steam
label
avro
docker-swarm
search-engine
automated-tests
algorithmic-trading
java-home
bro
i2c
eval
android-source
wordpress-theming
uiview
eclipse-luna
medium-editor
redux-observable
ng2-dragula
cruisecontrol.net
prediction
net-snmp
vertex-buffer
smart-mobile-studio
oracle-xml-db
mapguide
ntfs-mft
brute-force
lexical-analysis
microdata
google-account
android-maps-v2
tango
service-fabric-stateful
finite-element-analysis
stress-testing
production-environment
nstouchbar
webdatagrid
jgraph
azureportal
spring-data-hadoop
rollback
slot
google-maps-ios
gce
selenium-firefoxdriver
emoticons
garrys-mod
barcode-printing
objloader
payu
nsfetchedresultscontrolle
vst
update-site
dojox.charting
boost-hana
listadapter
image-editing
spatial-query
django-south
asp.net-mvc-2
web-essentials
mirrorlink
selendroid
python-winshell
httpie
jquery-autocomplete
firebug-lite
genetic-programming
libssh2
getimagedata
adaptive-compression
colt
json-patch
ng-hide
entity-framework-4.1
soa-suite
reporting-tools
phpsh
pys60
code-conversion
n-layer
getusermedia
file-exists
mysql-error-1045
datamember
nvelocity
pantheios
jquery-ui-button
mvvm-foundation
multibyte-functions
windows-controls
lazy-c++
castle-validators
data-execution-prevention

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