Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Exception handling in Python #7

Closed
tedmalone opened this issue Jun 5, 2013 · 1 comment
Closed

Exception handling in Python #7

tedmalone opened this issue Jun 5, 2013 · 1 comment

Comments

@tedmalone
Copy link

I've been experimenting with the python tutorials for sending data to Xively from python. The tutorial code didn't seem to include enough exception handling in some areas, and it's not clear to me how to determine where to add the exception handling. For instance, I received this crash log:

    datastream = feed.datastreams.create(channel, tags="pool")
  File "/usr/local/lib/python2.7/dist-packages/xively/managers.py", line 414, in create
    response.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 683, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 422 Client Error:

which seems to indicate that the stream creation failed. Note that it really never should have gotten to feed.datastreams.create() because it was actually an except: after a failed feed.datastreams.get() which shouldn't have failed. The tutorial suggested this:

  try:
    datastream = feed.datastreams.get(channel)
    return datastream
  except:
    print "Creating channel:", channel
    datastream = feed.datastreams.create(channel, tags="pool")
    return datastream

So, maybe I should do this? :

  try:
    datastream = feed.datastreams.get(channel)
    return datastream
  except:
    print "Creating channel:", channel
    try:
      datastream = feed.datastreams.create(channel, tags="pool")
      return datastream
    except:
      print "HTTPError({0}): {1}".format(e.errno, e.strerror)
@errordeveloper
Copy link
Contributor

I suppose this is pretty much the same as what described in #8, so please keep an eye on #5 and the next release-candidate.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants