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

How to identify customer with stripe webhook in Python/Flask
How to correctly implement a game manager in Python
How to convert a set of gps points to GPX file
NameError: name 'tree' is not defined
plotting 2d colored grid (eg. pcolormesh) in 3d-plane
Check if a system of inequalities entails another system of equalities?
TCP: Python client hangs when tries to write to C server
Working with columns in pandas
My Pygame image not loading
Python Tornado JSON Stream
how to print the matched words in python
python scrapy shell on macosx :: selenium.webdriver.common.action_chains.ActionChains at 0x1060d8bd0
How do I call my functions correctly in python?
TensorFlow module cant be found. even though its installed on Anancoda
Pandas group by filter based on conditions
How do I find all the businesses names and ids and urls using yelp api?

Categories

HOME
ember.js
cil
answer-set-programming
puzzle
mapping
paramiko
aem
google-sheets-api
transparent
codeeffects
yocto
google-classroom
getorgchart
cockroachdb
google-openid
aptana
ms-access-2007
multiple-columns
hhvm
rworldmap
myob
pdfsharp
rhmap
spring-data-neo4j
modelandview
body-parser
rhomobile
node-horseman
strstr
parent
web-development-server
react-native-router-flux
control-flow-graph
paho
matlab-cvst
lirc
tuleap
number-theory
jenkins-jira-trigger
pluck
forerunnerdb
pagefile
photography
redux-router
ingres
restivejs
onresume
sql-server-administration
gradle-script-kotlin
cron-task
children
dts
jackson-databind
database-backups
emokit
qt-linguist
xmp
cctray
document-oriented-db
response-headers
js-cookie
sevenzipsharp
programming-paradigms
stream-framework
type-mismatch
ibm-data-studio
apache-mina
web-component-tester
libsndfile
docopt
ember-addon
getimagedata
sgml
indexing-service
xenocode
uipickerviewcontroller
java.util.date
nservicebus4
onselect
getusermedia
mpmovieplayer
legacy-code
jquery-selectbox
objectbrowser
printing-web-page
scalaxb
chatroom
getresource
revert
front-controller
act
kpi
system-codedom-compiler
web-analytics-tools
hardware-infrastructure

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