Coder Social home page Coder Social logo

asyncio-apns's People

Contributors

andreyoparin avatar etataurov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

asyncio-apns's Issues

KeyError when underlying HTTP response is received

I'm getting the following traceback when trying to essentially follow the minimal example from the README:

» venv/bin/python test_justin.py
Exception in callback _SelectorSocketTransport._read_ready()
handle: <Handle _SelectorSocketTransport._read_ready()>
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/selector_events.py", line 730, in _read_ready
    self._protocol.data_received(data)
  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/sslproto.py", line 514, in data_received
    self._app_protocol.data_received(chunk)
  File "/Users/roy/tmp/apns/venv/lib/python3.6/site-packages/asyncio_apns/h2_client.py", line 101, in data_received
    self.handle_response(event.stream_id)
  File "/Users/roy/tmp/apns/venv/lib/python3.6/site-packages/asyncio_apns/h2_client.py", line 204, in handle_response
    status_code = int(headers[":status"])

If I set a breakpoint at that location, headers, somewhat oddly, seems to contain bytestrings:

» venv/bin/python test_justin.py
> /Users/roy/tmp/apns/test_justin.py(12)send_push()
     11     import ipdb; ipdb.set_trace()
---> 12     apns = await connect(CERT_FILE, KEY_FILE, development=True, loop=loop)
     13     result = await apns.send_message(message, token)

ipdb> b /Users/roy/tmp/apns/venv/lib/python3.6/site-packages/asyncio_apns/h2_client.py:204
Breakpoint 1 at /Users/roy/tmp/apns/venv/lib/python3.6/site-packages/asyncio_apns/h2_client.py:204
ipdb> c
> /Users/roy/tmp/apns/venv/lib/python3.6/site-packages/asyncio_apns/h2_client.py(204)handle_response()
    203         data = data_event.data if data_event is not None else None
1-> 204         status_code = int(headers[":status"])
    205         if status_code != 200:

ipdb> p headers
{b':status': b'200', b'apns-id': b'< redacted >'}

…which is weird. I would expect an HTTP library to decode the received headers into strings (str) since that's the appropriate data type for that. (That is, headers seems to not be decoded enough; the code seems correct to reference the header as ':status')

Python 3.6 tests failure

Needs investigation


=================================== FAILURES ===================================
______________________________ test_send_message _______________________________

apns_connect = <function apns_connect.<locals>.connector at 0x7ff38af6a0d0>

    @pytest.mark.asyncio
    def test_send_message(apns_connect):
        connection = yield from apns_connect()
        token = "abcde"
        message = "Hello"
        connection.protocol.send_request.return_value = future_with_result(
            (mock.MagicMock(), mock.MagicMock()))
>       yield from connection.send_message(message, token)

tests/test_connection.py:86: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <asyncio_apns.apns_connection.APNsConnection object at 0x7ff38af75128>
payload = 'Hello', token = 'abcde'
priority = <NotificationPriority.immediate: 10>, topic = None

    @asyncio.coroutine
    def send_message(self, payload: Union[Payload, str], token: str,
                     priority: NotificationPriority = NotificationPriority.immediate,
                     topic: str=None):
        if not self.connected:
            yield from self.connect()
        headers, data = self._prepare_request(payload, token, priority, topic)
        try:
>           headers, _ = yield from self.protocol.send_request(headers, data)
E           ValueError: not enough values to unpack (expected 2, got 0)

Better explaination with asyncio

Hi,

Your example is about sending a simple push, but in major case we need to send thousand of pushs.

I have a problem with it. I use a Semaphore for sending 50 pushs in concurrency (without it it's so slow ! about 2 pushs / sec) but i can't catch a bad token.

EG: I have a test push server, and with 188th push, i send back a 400: BadToken error.

Client side, i got the error but not for the good push/token (190th, 192th, even 189th but not the good one (188)

I have read there are something with "futures" but don't see many good examples on web about handling / playing with that.

My current testing code:

async def send_push4(apns, message, token):
    with await mysem:
        try:
            await apns.send_message(message, token)
        except Exception as APNsError:
            print("Error %s for %s" %(APNsError.status, token))


loop = asyncio.get_event_loop()
sem = asyncio.Semaphore(50)
for i in range(1,200):
        tasks.append(asyncio.async(send_push4(apns, message, token)))
loop.run_until_complete(asyncio.tasks)

Thanks for helping.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.