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

hyper dependency is no longer maintained #126

Open
kevindice opened this issue Mar 25, 2021 · 26 comments
Open

hyper dependency is no longer maintained #126

kevindice opened this issue Mar 25, 2021 · 26 comments

Comments

@kevindice
Copy link

As of January, hyper is no longer maintained:
python-hyper/hyper@b77e758

The readme recommends switching to httpx

@levy42
Copy link

levy42 commented Mar 26, 2021

also hyper requires h2 <3.0, which causes problems using other libraries that need h2>=3.0.
I'm facing an issue using hypercorn.

@kevindice
Copy link
Author

kevindice commented Mar 26, 2021

My conflict was with Twisted and the http2 extras installed. (Twisted[http2])
Also h2

@thierryba
Copy link

thierryba commented Apr 15, 2021

Also bothered by this...

@CodeMonk
Copy link

I started looking into what it would take to port from hyper -> httpx, and it's not THAT bad, but, it does take some knowledge of the innerworkings of both packages.

Is anyone doing this? Now knowing hyper or httpx, I'm probably not the best person to do it, but, I do need it done . . . ;-)

Thoughts?

-Dave

@mcepl
Copy link

mcepl commented May 1, 2021

Yes, I know, @CodeMonk specifically says CodeMonk@a1a3d59 is completely untested and dangerous, but if anybody would have means how to test it, it would be better if the patch was known.

@CodeMonk
Copy link

CodeMonk commented May 3, 2021

I tested it, and declined the PR. Wasn't even close to a full solution. If anyone knows hyper or httpx, they could better evaluate how much the lift would be.

I may have some cycles to try to improve my port later.

@erwan-lemonnier
Copy link

@CodeMonk I have a proper testing environment (staging env with sandboxed apps to play with) and am willing to help, bcz we badly need it. What's the status on your PR? Why did you decline it?

@erwan-lemonnier
Copy link

FYI, found 2 forks where hyper was replaced with httpx:
https://github.com/pocketlabs/PyAPNs2
https://github.com/karlwnw/PyAPNs2

@whardeman
Copy link

Good find, @erwan-lemonnier ! Please do share your experience here if you try either of those. I took a look at the first link and the footprint appears to be reasonably small.

@mcepl
Copy link

mcepl commented Sep 14, 2021

FYI, found 2 forks where hyper was replaced with httpx:
https://github.com/pocketlabs/PyAPNs2

pocketlabs@f1220b8 doesn’t let PyAPNs2 pass its test suite.

https://github.com/karlwnw/PyAPNs2

https://github.com/karlwnw/PyAPNs2/tree/feature/httpx seems like MUCH more invasive and the last commit is still marked as WIP.

@jayvdb
Copy link

jayvdb commented Oct 19, 2021

ping @karlwnw & @kitdesai

https://github.com/CodeMonk/PyAPNs2/tree/feature/port-to-httpx is @CodeMonk's port.

https://github.com/chrigu/PyAPNs2/tree/feature/httpx is another port by @chrigu

Worth noting that several libraries using apns2 have switched to using https://github.com/Fatal1ty/aioapns , which only depends on h2,pyopenssl&pyjwt rather than httpx which has a large dependency tree (see https://www.wheelodex.org/projects/httpx/ ).

@jayvdb
Copy link

jayvdb commented Jan 9, 2022

ping everyone , has any of these ports progressed at all?

@chrigu
Copy link

chrigu commented Jan 9, 2022

@jayvdb I just made the parts working that I needed for my project and my port won't be developed any further.

@erwan-lemonnier
Copy link

And we replaced PyAPNs2 with aioapns, which required a bit of extra work to make sure threads are properly initialised but works really well with python >= 3.8

@daveisfera
Copy link

Any chance of a release?

@github-actions
Copy link

github-actions bot commented Nov 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Nov 8, 2022
@jayvdb
Copy link

jayvdb commented Nov 8, 2022

There is some progress at #149

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label May 11, 2023
@daveisfera
Copy link

This is still an issue

@github-actions github-actions bot removed the stale label May 12, 2023
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Nov 11, 2023
@daveisfera
Copy link

This is still an issue

@github-actions github-actions bot removed the stale label Nov 12, 2023
@ssyberg
Copy link

ssyberg commented Mar 13, 2024

Still an issue!

@salty-horse
Copy link

Don't expect much to happen when you announce it's still an issue on a stale issue of an unmaintained package.

You're welcome to use my PR, which works on modern versions of Python. (I suggest forking it because I can't guarantee my branch will live forever)
#149

@ssyberg
Copy link

ssyberg commented Mar 13, 2024

Yea, looks like for anyone having this issue related to django-push-notifications, there's a fix on the verge of merge: jazzband/django-push-notifications#696

@ajans
Copy link

ajans commented Aug 9, 2024

When migrating to python 3.11, I basically did a self-supported implementation of an apns-client based on httpx and certificate-authentication (pem-file) (so please, don't expect any support for this from me if this doesn't work for you).
The only thing I took from this library is the errors.py to have a solid error-handling, the same as using this PyAPNS2-library.

https://gist.github.com/ajans/b56353067cc3ad8abbfb35c083ef4a5b

  1. This implementation expects a valid module-path in the variable pem_path to a certificate-file (pem-file) in your source-tree, adapt if you need other path-types
  2. proxy-support: client.py looks for the env-variable https_proxy and adds the http://-prefix if it is set without that.
  3. connections: the httpx-client is configured to only create 1 standing connection without expiry, as the apple-documentation states, this should be enough for most use-cases. If you need more, adapt to your needs.

The method init_apns_before_retry is meant for those cases, where e.g. the apple-service resets or discards their side of the connection. In my code using this, I annotate the _send_push_apple method with a tenacity.retry-annotation to use this init-method before a retry, to reset the connection into working state (1 retry is always enough to reset the connection, but you might adapt to your needs).
The send_push_apple method itself should return the status-code PUSHSTATUS_ERROR_RETRY if it catches a connection-issue to reset the connection:

import <your_package>.apns.client as _apns_client

@_tenacity.retry(
    before_sleep=_apns_client.init_apns_before_retry,
    wait=_tenacity.wait_random(min=1, max=2),
    before=_tenacity.before_log(_log, _logging.WARNING),
    retry=_tenacity.retry_if_result(lambda value: value == PUSHSTATUS_ERROR_RETRY),
    stop=_tenacity.stop_after_attempt(2),
    retry_error_callback=_give_up_retry,
)
def _send_push_apple(
    request,
    push_token,
    apple_payload,
    apple_custom,
    dev,
):
    push_token = push_token_schema.validate(push_token)

    # Send a notification
    status = PUSHSTATUS_OK
    try:
        _log.debug(
            "trying to send apple-push %s to push-token %s",
            str(apple_payload),
            push_token,
        )
        _apns_client.send_notification(push_token, apple_payload, apple_custom, dev)
    # ... don't forget to catch and handle APNS-errors like "BadDeviceToken" and "Unregistered" ...
    except (
        BrokenPipeError,
        _ssl.SSLError,
        _httpx.RequestError,
    ) as exc:
        # another retryable error happened
        status = PUSHSTATUS_ERROR_RETRY
        _log.error(
            "apple-push with %s to push-token %s failed with retryable error %s",
            str(apple_payload),
            push_token,
            str(exc),
        )

    return status


# noinspection PyUnusedLocal
def _give_up_retry(retry_state):  # pylint: disable=unused-argument
    _log.error("This was the last attempt, giving up")
    return PUSHSTATUS_ERROR

Maybe this code-snippet might not be easy to integrate into your project, so maybe it would be better to migrate the PyAPNs2-code here or in a fork to use something like this.

But since I don't have the time or energy to do it myself and don't want to constantly ask for support here, I thought it might be good idea to share these snippets with you, since PyAPNS2 helped me a lot before with the initial implementation with older python-versions and I wanted to give something back that might be helpful with these stuck dependencies.

@JelleZijlstra
Copy link

I started a project https://pypi.org/project/compat-fork-apns2/ aiming to update this project for newer versions of Python. Unfortunately, I don't have enough time and expertise to finish switching away from hyper, but if someone else is interested in contributing code or helping to maintain the fork, please let me know at compat-fork#3.

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

No branches or pull requests