sendgrid-django icon indicating copy to clipboard operation
sendgrid-django copied to clipboard

SSL Verification Failure on Docker Alpine Python 3.5

Open digitaldavenyc opened this issue 8 years ago • 8 comments

We are trying to get setup with Send Grid using this library and receiving the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/celery/app/trace.py", line 240, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/usr/lib/python3.5/site-packages/celery/app/trace.py", line 438, in __protected_call__
    return self.run(*args, **kwargs)
  File "/var/doorman/communication/tasks.py", line 34, in send
    mail.send()
  File "/usr/lib/python3.5/site-packages/django/core/mail/message.py", line 342, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/lib/python3.5/site-packages/sgbackend/mail.py", line 68, in send_messages
    self.sg.client.mail.send.post(request_body=mail)
  File "/usr/lib/python3.5/site-packages/python_http_client/client.py", line 204, in http_request
    return Response(self._make_request(opener, request))
  File "/usr/lib/python3.5/site-packages/python_http_client/client.py", line 138, in _make_request
    return opener.open(request)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1297, in https_open
    context=self._context, check_hostname=self._check_hostname)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)>

Our setup is:

  • Django 1.10
  • Python 3.5
  • Docker
  • Alpine OS (latest)

digitaldavenyc avatar Dec 20 '16 16:12 digitaldavenyc

@digitaldavenyc Can you please show me your Dockerfile?

andriisoldatenko avatar Dec 20 '16 18:12 andriisoldatenko

Sure

FROM alpine

ENV PYTHONPATH $PYTHONPATH:/var/myapp

WORKDIR /var/myapp

COPY . ./

RUN apk add --no-cache --update wget python3 python3-dev ca-certificates musl-dev libc-dev gcc bash postgresql-dev && \
    python3 -m ensurepip && \
    pip3 install --upgrade pip setuptools

RUN rm -r /root/.cache && \
    rm -r /usr/lib/python*/ensurepip

RUN pip3 install --upgrade pip && \
    pip3 install -r requirements-dev.txt

EXPOSE 8030

CMD gunicorn --reload --bind 0.0.0.0:8030 --pythonpath '/var/myapp' myapp.wsgi:application

digitaldavenyc avatar Dec 20 '16 18:12 digitaldavenyc

@digitaldavenyc What is sendgrid-django and python-sedngrid versions?

andriisoldatenko avatar Dec 20 '16 21:12 andriisoldatenko

sendgrid-django==4.0.4
python-sendgrid==3.6.3

digitaldavenyc avatar Dec 20 '16 21:12 digitaldavenyc

That seems like an error from the SG client. More specifically, looks like an issue from the API itself. @thinkingserious any insights?

elbuo8 avatar Jan 17 '17 12:01 elbuo8

@elbuo8,

Hopefully the last comment on this thread will help: https://github.com/sendgrid/sendgrid-python/issues/229

thinkingserious avatar Jan 18 '17 05:01 thinkingserious

+1

hugotox avatar Jun 13 '17 20:06 hugotox

This seems to be a solution: https://stackoverflow.com/a/42334357

thinkingserious avatar Jun 13 '17 20:06 thinkingserious