Ensure all json loads calls use strings
This commit is contained in:
parent
cf3b9782ac
commit
e0e4d4c87f
|
@ -86,8 +86,12 @@ def soundcloud_download(token, callback_url, api_key, track_id):
|
|||
auth=requests.auth.HTTPBasicAuth(api_key, ""),
|
||||
)
|
||||
re.raise_for_status()
|
||||
try:
|
||||
response = re.content.decode()
|
||||
except (UnicodeDecodeError, AttributeError):
|
||||
response = re.content
|
||||
f = json.loads(
|
||||
re.content
|
||||
response
|
||||
) # Read the response from the media API to get the file id
|
||||
obj["fileid"] = f["id"]
|
||||
else:
|
||||
|
@ -203,8 +207,12 @@ def podcast_download(
|
|||
auth=requests.auth.HTTPBasicAuth(api_key, ""),
|
||||
)
|
||||
re.raise_for_status()
|
||||
try:
|
||||
response = re.content.decode()
|
||||
except (UnicodeDecodeError, AttributeError):
|
||||
response = re.content
|
||||
f = json.loads(
|
||||
re.content
|
||||
response
|
||||
) # Read the response from the media API to get the file id
|
||||
obj["fileid"] = f["id"]
|
||||
obj["status"] = 1
|
||||
|
|
|
@ -27,6 +27,10 @@ class CuePointAnalyzer(Analyzer):
|
|||
command = [CuePointAnalyzer.SILAN_EXECUTABLE, '-b', '-F', '0.99', '-f', 'JSON', '-t', '1.0', filename]
|
||||
try:
|
||||
results_json = subprocess.check_output(command, stderr=subprocess.STDOUT, close_fds=True)
|
||||
try:
|
||||
results_json = results_json.decode()
|
||||
except (UnicodeDecodeError, AttributeError):
|
||||
pass
|
||||
silan_results = json.loads(results_json)
|
||||
|
||||
# Defensive coding against Silan wildly miscalculating the cue in and out times:
|
||||
|
|
|
@ -157,6 +157,10 @@ class MessageListener:
|
|||
We avoid cascading failure this way.
|
||||
'''
|
||||
try:
|
||||
try:
|
||||
body = body.decode()
|
||||
except (UnicodeDecodeError, AttributeError):
|
||||
pass
|
||||
msg_dict = json.loads(body)
|
||||
api_key = msg_dict["api_key"]
|
||||
callback_url = msg_dict["callback_url"]
|
||||
|
|
|
@ -137,7 +137,11 @@ class ApiRequest(object):
|
|||
|
||||
try:
|
||||
if content_type == 'application/json':
|
||||
data = json.loads(response)
|
||||
try:
|
||||
response = response.decode()
|
||||
except (UnicodeDecodeError, AttributeError):
|
||||
pass
|
||||
data = json.loads(response.decode)
|
||||
return data
|
||||
else:
|
||||
raise InvalidContentType()
|
||||
|
|
|
@ -78,6 +78,10 @@ class PypoFetch(Thread):
|
|||
try:
|
||||
self.logger.info("Received event from Pypo Message Handler: %s" % message)
|
||||
|
||||
try:
|
||||
message = message.decode()
|
||||
except (UnicodeDecodeError, AttributeError):
|
||||
pass
|
||||
m = json.loads(message)
|
||||
command = m['event_type']
|
||||
self.logger.info("Handling command: " + command)
|
||||
|
|
|
@ -64,6 +64,10 @@ class PypoMessageHandler(Thread):
|
|||
try:
|
||||
self.logger.info("Received event from RabbitMQ: %s" % message)
|
||||
|
||||
try:
|
||||
message = message.decode()
|
||||
except (UnicodeDecodeError, AttributeError):
|
||||
pass
|
||||
m = json.loads(message)
|
||||
command = m['event_type']
|
||||
self.logger.info("Handling command: " + command)
|
||||
|
|
|
@ -197,7 +197,11 @@ class Recorder(Thread):
|
|||
def handle_message(self):
|
||||
if not self.queue.empty():
|
||||
message = self.queue.get()
|
||||
msg = json.loads(message)
|
||||
try:
|
||||
message = message.decode()
|
||||
except (UnicodeDecodeError, AttributeError):
|
||||
pass
|
||||
msg = json.loads(message)
|
||||
command = msg["event_type"]
|
||||
self.logger.info("Received msg from Pypo Message Handler: %s", msg)
|
||||
if command == 'cancel_recording':
|
||||
|
|
Loading…
Reference in New Issue