0

My Python code opens up a few WAV files and puts them into a base64 encoded string then sends to a server via HTTP. Every 50 transmissions or so some encWAV string data loses its "=" padding. I end up with data in fullBase64Data and some of the segments have the correct padding and others do not. I can't figure out a rhyme or reason to this. What is causing this and how can I fix the issue?

f = open(requestID + '/' + str(i) + '.wav', 'rb')
encWAV = b64encode(f.read())
f.close()
fullBase64Data = fullBase64Data + "::SPLITWAV::" + encWAV.decode('ascii');


url = 'http://REMOVED.com/queue/removed.php';
post_fields = {'RequestID': requestID, 'AudioData': fullBase64Data,'AgentName': agentName};


request = Request(url, urllib.urlencode(post_fields).encode());

1 Answers1

0

= are only used to pad the result to a multiple of 4 characters. If the data happens to convert to such a multiple, you won't get any = at the end. See also: Why does base64 encoding requires padding if the input length is not divisible by 3?

Also, ITYM urllib.parse.urlencode?

Community
  • 1
  • 1
Tom Zych
  • 13,329
  • 9
  • 36
  • 53