mirror of
https://github.com/sivel/speedtest-cli.git
synced 2026-08-03 22:29:08 +00:00
Make sure we are only sending ascii characters in POST requests to avoid urllib2 encoding errors, and add the missed post var in the POST data
This commit is contained in:
parent
9e1a582826
commit
6c33c1eb24
2 changed files with 8 additions and 3 deletions
|
|
@ -107,7 +107,9 @@ def downloadSpeed(files):
|
|||
class FilePutter(threading.Thread):
|
||||
def __init__(self, url, start, size):
|
||||
self.url = url
|
||||
self.data = os.urandom(int(size)-len('content1='))
|
||||
data = os.urandom(int(size)).encode('hex')
|
||||
self.data = 'content1=%s' % data[0:int(size)-9]
|
||||
del data
|
||||
self.result = None
|
||||
self.starttime = start
|
||||
threading.Thread.__init__(self)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import os
|
|||
import sys
|
||||
import hashlib
|
||||
import threading
|
||||
import binascii
|
||||
from queue import Queue
|
||||
|
||||
|
||||
|
|
@ -103,7 +104,9 @@ def downloadSpeed(files):
|
|||
class FilePutter(threading.Thread):
|
||||
def __init__(self, url, start, size):
|
||||
self.url = url
|
||||
self.data = os.urandom(int(size)-len('content1='))
|
||||
data = binascii.hexlify(os.urandom(int(size)-9)).decode()
|
||||
self.data = 'content1=%s' % data[0:int(size)-9]
|
||||
del data
|
||||
self.result = None
|
||||
self.starttime = start
|
||||
threading.Thread.__init__(self)
|
||||
|
|
@ -114,7 +117,7 @@ class FilePutter(threading.Thread):
|
|||
def run(self):
|
||||
try:
|
||||
if (time.time() - self.starttime) <= 10:
|
||||
f = urllib.request.urlopen(self.url, self.data)
|
||||
f = urllib.request.urlopen(self.url, self.data.encode())
|
||||
contents = f.read()
|
||||
f.close()
|
||||
self.result = self.data
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue