why not simply: `agent = request.META.get('HTTP_USER_AGENT', '')`?

I tend to try to avoid bare except clauses if at all possible.

Maybe something like:

```python

def get_request_header(request, header_name):
    if request is None or not hasattr(request, 'META') or header_name not in request.META:
        return ''
    else:
        return request.META[header_name]

event = {
    "ip": get_request_header(request, 'REMOTE_ADDR'),
    "host": get_request_header(request, 'SERVER_NAME'),
}
```