Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError in MailgunTrackingWebhookView.esp_to_anymail_event #62

Closed
klette opened this issue Apr 27, 2017 · 2 comments
Closed

ValueError in MailgunTrackingWebhookView.esp_to_anymail_event #62

klette opened this issue Apr 27, 2017 · 2 comments

Comments

@klette
Copy link

klette commented Apr 27, 2017

Given the following esp_event from a Mailgun webhook:

{
'attachment-count': '1', 
'code': '5.1.1', 
'domain': 'mg.otovo.no', 
'error': 'smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found', 
'message-headers': '[["Received", "from drex02.felles.ds.nrk.no (2002:a043:8763::a043:8763) by MAEX02.felles.ds.nrk.no (2002:a043:8797::a043:8797) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 26 Apr 2017 21:40:34 +0200"], ["Received", "from EUR02-VE1-obe.outbound.protection.outlook.com (213.199.154.48) by drex02.felle..., 
'message-id': 'xxx@mg.otovo.no', 
'tag': 'calculation', 
'token': 'exxx'
}

esp_to_anymail_event fails with a ValueError trying to turn '5.1.1' into an int.

Stacktrace:

ValueError: invalid literal for int() with base 10: '5.1.1'
  File "django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "django/utils/decorators.py", line 67, in _wrapper
    return bound_func(*args, **kwargs)
  File "django/views/decorators/csrf.py", line 58, in wrapped_view
    return view_func(*args, **kwargs)
  File "django/utils/decorators.py", line 63, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "anymail/webhooks/base.py", line 109, in dispatch
    return super(AnymailBaseWebhookView, self).dispatch(request, *args, **kwargs)
  File "django/views/generic/base.py", line 88, in dispatch
    return handler(request, *args, **kwargs)
  File "anymail/webhooks/base.py", line 123, in post
    events = self.parse_events(request)
  File "anymail/webhooks/mailgun.py", line 41, in parse_events
    return [self.esp_to_anymail_event(request.POST)]
  File "anymail/webhooks/mailgun.py", line 91, in esp_to_anymail_event
    mta_status = int(esp_event['code'])

This might be a mailgun bug as well :)

@medmunds
Copy link
Contributor

Hmm, Mailgun's event code has always been documented to be x.y.z, but in actual testing had been a three-digit integer. Looks like Mailgun's implementation finally caught up to their docs. (The raw_event data in Anymail's test_mailgun_webhooks was all derived from actual webhook events.)

I'll need to repeat some live testing to see what they're actually sending now for various bounce/failure event codes.

@medmunds
Copy link
Contributor

medmunds commented May 4, 2017

I've been trying to replicate this, and it seems like--despite Mailgun's docs--the three-digit integer error codes are also still common. (Both in their webhook test posts and from sends to several ISPs.)

I guess I'll code it up to accept either format.

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

No branches or pull requests

2 participants