summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Copeland <ben.copeland@linaro.org>2018-01-15 19:07:50 +0000
committerBen Copeland <ben.copeland@linaro.org>2018-01-15 20:37:24 +0000
commit6be53432d0eaf3cf6014acebe2fdeba65817ab7a (patch)
tree8024744919b61f9ecd3967fad7dfab2b8b3f8a09
parenta02a906b1770a7d39bbe8d456e78b849374636f9 (diff)
downloadpublishing-api-master.tar.gz
0 byte issueHEADmaster
After some testing I noticed using files=f instead of data=f caused the 0 byte file to go away because it was adding 38 bytes of data. Using requests you can modify the headers and as such we can just delete the Transfer-Encoding header which should not be set for 0 byte files. Change-Id: Ice9dc3dfe810d17d4b2effcf90e255e270752ecb
-rwxr-xr-xlinaro-cp.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/linaro-cp.py b/linaro-cp.py
index 9888d2b..c77998d 100755
--- a/linaro-cp.py
+++ b/linaro-cp.py
@@ -145,12 +145,15 @@ class API_v3(API_v1):
try:
with open(filename, 'rb') as f:
print("Uploading file %s" % filename)
+ s = requests.Session()
+ req = requests.Request('PUT', url, data=f, headers=headers)
+ prepped = req.prepare()
if size == 0:
- # Due to a request bug we need to use files system call
- # to get around https://github.com/requests/requests/issues/1648
- resp = requests.put(url, headers=headers, files=f, timeout=61)
- else:
- resp = requests.put(url, headers=headers, data=f, timeout=61)
+ # Due to a Python bug "Transfer-Encoding: chucked" gets
+ # added to 0 byte files.
+ # https://github.com/requests/requests/issues/1648
+ del prepped.headers['Transfer-Encoding']
+ resp = s.send(prepped, timeout=61)
if resp.status_code in (200, 201):
return
else: