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:
Matt Martz 2013-01-12 10:46:56 -06:00
parent 9e1a582826
commit 6c33c1eb24
2 changed files with 8 additions and 3 deletions

View File

@ -107,7 +107,9 @@ def downloadSpeed(files):
class FilePutter(threading.Thread): class FilePutter(threading.Thread):
def __init__(self, url, start, size): def __init__(self, url, start, size):
self.url = url 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.result = None
self.starttime = start self.starttime = start
threading.Thread.__init__(self) threading.Thread.__init__(self)

View File

@ -25,6 +25,7 @@ import os
import sys import sys
import hashlib import hashlib
import threading import threading
import binascii
from queue import Queue from queue import Queue
@ -103,7 +104,9 @@ def downloadSpeed(files):
class FilePutter(threading.Thread): class FilePutter(threading.Thread):
def __init__(self, url, start, size): def __init__(self, url, start, size):
self.url = url 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.result = None
self.starttime = start self.starttime = start
threading.Thread.__init__(self) threading.Thread.__init__(self)
@ -114,7 +117,7 @@ class FilePutter(threading.Thread):
def run(self): def run(self):
try: try:
if (time.time() - self.starttime) <= 10: 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() contents = f.read()
f.close() f.close()
self.result = self.data self.result = self.data