From 80cb5567d50b4898c6b95c508a9fc5b8cab52216 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Wed, 31 Jan 2018 17:12:43 -0600 Subject: [PATCH] Show error messages in failed audio uploads. Hopefully Fixes api uploads in sndup --- src/controller/messages.py | 7 +++++-- src/extra/AudioUploader/audioUploader.py | 2 +- src/extra/AudioUploader/transfer.py | 13 ++++++++++++- src/wxUI/commonMessageDialogs.py | 3 +++ 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/controller/messages.py b/src/controller/messages.py index 09abad2f..418756bb 100644 --- a/src/controller/messages.py +++ b/src/controller/messages.py @@ -10,6 +10,8 @@ import sound from pubsub import pub if system == "Windows": from wxUI.dialogs import message, urlList + from wxUI import commonMessageDialogs + from extra import translator, SpellChecker, autocompletionUsers from extra.AudioUploader import audioUploader elif system == "Linux": @@ -114,11 +116,12 @@ class basicTweet(object): url = dlg.uploaderFunction.get_url() pub.unsubscribe(dlg.uploaderDialog.update, "uploading") dlg.uploaderDialog.destroy() - if url != 0: + if "sndup.net/" in url: self.message.set_text(self.message.get_text()+url+" #audio") self.text_processor() else: - output.speak(_(u"Unable to upload the audio")) + commonMessageDialogs.common_error(url) + dlg.cleanup() dlg = audioUploader.audioUploader(self.session.settings, completed_callback) self.message.text_focus() diff --git a/src/extra/AudioUploader/audioUploader.py b/src/extra/AudioUploader/audioUploader.py index 8f812701..afc0fee1 100644 --- a/src/extra/AudioUploader/audioUploader.py +++ b/src/extra/AudioUploader/audioUploader.py @@ -52,7 +52,7 @@ class audioUploader(object): self.uploaderDialog = wx_transfer_dialogs.UploadDialog(self.file) output.speak(_(u"Attaching...")) if self.dialog.get("services") == "SNDUp": - base_url = "http://sndup.net/post.php" + base_url = "https://sndup.net/post.php" if len(self.config["sound"]["sndup_api_key"]) > 0: url = base_url + '?apikey=' + self.config['sound']['sndup_api_key'] else: diff --git a/src/extra/AudioUploader/transfer.py b/src/extra/AudioUploader/transfer.py index 080d00d4..aef2c42c 100644 --- a/src/extra/AudioUploader/transfer.py +++ b/src/extra/AudioUploader/transfer.py @@ -55,6 +55,7 @@ class Upload(object): def perform_transfer(self): log.debug("starting upload...") self.start_time = time.time() + print self.url self.response=requests.post(url=self.url, data=self.monitor, headers={"Content-Type":self.m.content_type}, allow_redirects=self.follow_location, stream=True) log.debug("Upload finished.") self.complete_transfer() @@ -69,5 +70,15 @@ class Upload(object): self.completed_callback(self.obj) if hasattr(self,'fin') and callable(self.fin.close): self.fin.close() + def get_url(self): - return self.response.json()['url'] + try: + data = self.response.json() + except: + return _("Error in file upload: {0}").format(self.data.content,) + if data.has_key("url") and data["url"] != "0": + return data["url"] + elif data.has_key("error") and data["error"] != "0": + return data["error"] + else: + return _("Error in file upload: {0}").format(self.data.content,) \ No newline at end of file diff --git a/src/wxUI/commonMessageDialogs.py b/src/wxUI/commonMessageDialogs.py index 539534d2..0219edd1 100644 --- a/src/wxUI/commonMessageDialogs.py +++ b/src/wxUI/commonMessageDialogs.py @@ -86,3 +86,6 @@ def delete_filter(): def existing_filter(): return wx.MessageDialog(None, _(u"This filter already exists. Please use a different title"), _(u"Error"), wx.OK).ShowModal() + +def common_error(reason): + return wx.MessageDialog(None, reason, _(u"Error"), wx.OK).ShowModal() \ No newline at end of file