Skip to content

Commit

Permalink
event-collector: Safely read response.reason
Browse files Browse the repository at this point in the history
Some versions of python requests don't have a response.reason field
  • Loading branch information
kemitche committed May 8, 2015
1 parent f3d2070 commit c486f17
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion r2/r2/lib/eventcollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ def publish(self, events):
yield resp, some_events


def _get_reason(response):
return (getattr(response, "reason", None) or
getattr(response.raw, "reason", "{unknown}"))


def process_events(g, timeout=5.0, max_event_size=4096, **kw):
publisher = EventPublisher(
g.events_collector_url,
Expand All @@ -250,7 +255,7 @@ def processor(msgs, chan):
g.log.warning(
"Event send failed %s - %s",
response.status_code,
response.reason,
_get_reason(response),
)
g.log.warning("Response headers: %r", response.headers)
response.raise_for_status()
Expand Down

0 comments on commit c486f17

Please sign in to comment.