From e73305c5cd04c4b4b9c8a7d50d0adba3136c908b Mon Sep 17 00:00:00 2001 From: liuxu Date: Sat, 1 Dec 2018 23:58:38 +0800 Subject: [PATCH] Fix python3 upload problem In python3, if Content-length is not set,urllib.request.AbstractHTTPHandler::do_request_() will use "Transfer-encoding:chunked", which will cause HTTPUploader not to exit until timeout --- speedtest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/speedtest.py b/speedtest.py index 7a99c99..199d7eb 100755 --- a/speedtest.py +++ b/speedtest.py @@ -1525,9 +1525,11 @@ class Speedtest(object): ) if pre_allocate: data.pre_allocate() + # Fix python3 upload problem: Add Content-length to avoid AbstractHTTPHandler use chunked + headers = {'Content-length': size} requests.append( ( - build_request(self.best['url'], data, secure=self._secure), + build_request(self.best['url'], data, secure=self._secure, headers=headers), size ) )