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