web-push-libs / pywebpush

Python Webpush Data encryption library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting this error when trying to get basic webpush() example to work: AttributeError: type object 'EllipticCurvePublicKey' has no attribute 'from_encoded_point'

mhb11 opened this issue · comments

commented

I am trying the example you've outlined in your README file.

The block of code I'm referring to is simply this:

try:
    webpush(
        subscription_info=subscription_info,
        data="Mary had a little lamb",
        vapid_private_key=PRIVATE_KEY,
        vapid_claims={
                "sub": "mailto:my_email@email.com",
            }
    )
except WebPushException as ex:
    print("I'm sorry, Dave, but I can't do that: {}", repr(ex))
    # Mozilla returns additional information in the body of the response.
    if ex.response and ex.response.json():
        extra = ex.response.json()
        print("Remote service replied with a {}:{}, {}",
              extra.code,
              extra.errno,
              extra.message
              )

subscription_info contains a dictionary like so:

{"endpoint": "https://updates.push.services.mozilla.com/push/v1/gAA...", "keys": {"auth": "k8J...", "p256dh": "BOr..."}}

And PRIVATE_KEY is a string private_key value I've retrieved from a secure location.

Just testing it out gives me the following error:

AttributeError: type object 'EllipticCurvePublicKey' has no attribute 'from_encoded_point' (full trace at the end).

Any idea what is going on? The Python version I'm testing this on is 2.7.6


Full trace:

Traceback (most recent call last):
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/newrelic-2.56.0.42/newrelic/hooks/framework_django.py", line 499, in wrapper
    return wrapped(*args, **kwargs)
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/contrib/auth/decorators.py", line 25, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/home/myuser/Desktop/myproject/myapp/push_notification_api.py", line 84, in send_push_notification
    "sub": "mailto:my_email@email.com",
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/pywebpush/__init__.py", line 419, in webpush
    timeout=timeout,
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/pywebpush/__init__.py", line 284, in send
    encoded = self.encode(data, content_encoding)
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/pywebpush/__init__.py", line 200, in encode
    version=content_encoding)
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/http_ece/__init__.py", line 375, in encrypt
    keyid=keyid, keylabel=keylabel)
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/http_ece/__init__.py", line 113, in derive_key
    keylabel=keylabel)
  File "/home/myuser/.virtualenvs/myenv/local/lib/python2.7/site-packages/http_ece/__init__.py", line 78, in derive_dh
    pubkey = ec.EllipticCurvePublicKey.from_encoded_point(
AttributeError: type object 'EllipticCurvePublicKey' has no attribute 'from_encoded_point'
commented

Upgrading to cryptography 2.5 (as pointed out here: home-assistant/core#21001) solves the issue (and puts me squarely in the 'warning' queue).