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

datastream.update() issue #8

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

datastream.update() issue #8

tedmalone opened this issue Jun 5, 2013 · 1 comment

Comments

@tedmalone
Copy link

Okay, here's another raise that confused me. The tutorial seemed to indicate that exceptions would be raised as HTTPError's, but this came through as a ConnectionError.

  File "/home/pi/pool/main/sendto_xively.py", line 36, in sendto_xively
    datastream.update()
  File "/usr/local/lib/python2.7/dist-packages/xively/models.py", line 234, in update
    self._manager.update(self.id, **state)
  File "/usr/local/lib/python2.7/dist-packages/xively/managers.py", line 425, in update
    response = self.client.put(url, data=kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 387, in put
    return self.request('PUT', url, data=data, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/xively/client.py", line 77, in request
    return super(Client, self).request(method, full_url, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 335, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/sessions.py", line 438, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests/adapters.py", line 327, in send
    raise ConnectionError(e)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='api.xively.com', port=80): Max retries exceeded with url: /v2/feeds/1905326953/datastreams/Spa (Caused by <class 'httplib.BadStatusLine'>: '')

The example suggested this would work:

  try:
    datastream.update()
  except requests.HTTPError as e:
    print "HTTPError({0}): {1}".format(e.errno, e.strerror)

Do I need to nest another try/except to handle the ConnectError()?

@errordeveloper
Copy link
Contributor

@tedmalone at the moment you will need to do something like:

  try:
    datastream.update()
  except (requests.HTTPError,  requests.ConnectError) as e:
    print "Error({0}): {1}".format(e.errno, e.strerror)

There is a discussion how this needs to be fixed #5.

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