[yt-svn] commit/yt: MatthewTurk: Add some error handling and display the returned shorturl.

Bitbucket commits-noreply at bitbucket.org
Thu May 10 04:41:10 PDT 2012


1 new commit in yt:


https://bitbucket.org/yt_analysis/yt/changeset/3442625bb24f/
changeset:   3442625bb24f
branch:      yt
user:        MatthewTurk
date:        2012-05-10 13:41:01
summary:     Add some error handling and display the returned shorturl.
affected #:  1 file

diff -r cb1c91fa33e87e778f992f2ff25c2e50849fcc96 -r 3442625bb24f66b1cd15273f7feb708342bad20a yt/utilities/minimal_representation.py
--- a/yt/utilities/minimal_representation.py
+++ b/yt/utilities/minimal_representation.py
@@ -113,7 +113,15 @@
                                              'api_key' : api_key})
         request = urllib2.Request(url, datagen, headers)
         # Actually do the request, and get the response
-        rv = urllib2.urlopen(request).read()
+        try:
+            rv = urllib2.urlopen(request).read()
+        except urllib2.HTTPError as ex:
+            if ex.code == 401:
+                mylog.error("You must create an API key before uploading.")
+                mylog.error("https://data.yt-project.org/getting_started.html")
+                return
+            else:
+                raise ex
         uploader_info = json.loads(rv)
         new_url = url + "/handler/%s" % uploader_info['handler_uuid']
         for i, (cn, cv) in enumerate(chunks):
@@ -128,8 +136,9 @@
 
         datagen, headers = multipart_encode({'status' : 'FINAL'})
         request = urllib2.Request(new_url, datagen, headers)
-        rv = urllib2.urlopen(request).read()
-        return json.loads(rv)
+        rv = json.loads(urllib2.urlopen(request).read())
+        mylog.info("Upload succeeded!  View here: %s", rv['url'])
+        return rv
 
 class FilteredRepresentation(MinimalRepresentation):
     def _generate_post(self):

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list