Giter VIP home page Giter VIP logo

aiofcm's People

Contributors

ak0nshin avatar fatal1ty avatar holyachon avatar lhadvantek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aiofcm's Issues

Can't send noti if use class FCM such as attribute in ViewSet (Django)

Below is my code but it not run send_messages function. Complier not raise any exceptions. Please.....
`class AsyncNotificationViewSet(ViewSet):
FCM_SENDER_ID = <FCM_SENDER_ID >
FCM_API_KEY = <FCM_API_KEY >
fcm = FCM(FCM_SENDER_ID, FCM_API_KEY)

async def send_message(self):
    print(self.fcm.pool.connections)
    message = Message(
        device_token=<device_token>,
        notification={
            "title": "Hello from Firebase",
            "body": "This is notification",
            "sound": "default"
        }
    )
    await self.fcm.send_message(message)
    print(self.fcm.pool.connections)
 
async def cron(self, request):
    try:
        loop = asyncio.get_event_loop()
        send_messages = [self.send_message() for _ in range(1)]
        res = await asyncio.wait(send_messages)
        return success_response()
    except Exception as e:
        print(e)
        return HttpResponse(str(e))`

Package breaks with python 3.1.3

Might need to update aioxmpp for the new anyio version?



/usr/local/lib/python3.11/site-packages/aiofcm/__init__.py:1: in <module>
--
  | from aiofcm.client import FCM
  | /usr/local/lib/python3.11/site-packages/aiofcm/client.py:4: in <module>
  | from aiofcm.connection import FCMConnectionPool
  | /usr/local/lib/python3.11/site-packages/aiofcm/connection.py:7: in <module>
  | import aioxmpp
  | /usr/local/lib/python3.11/site-packages/aioxmpp/__init__.py:101: in <module>
  | from .errors import (  # NOQA
  | /usr/local/lib/python3.11/site-packages/aioxmpp/errors.py:109: in <module>
  | class ErrorCondition(structs.CompatibilityMixin, xso.XSOEnumMixin, enum.Enum):
  | /usr/local/lib/python3.11/enum.py:557: in __new__
  | raise exc
  | /usr/local/lib/python3.11/enum.py:266: in __set_name__
  | raise new_exc
  | E   TypeError: _value_ not set in __new__, unable to create it


Throws Exception 'XMLStream' object has no attribute '_writer'

On running this code with numeric_sender_id, api_key and device_token, Throws error XMLStream object has no attribute '_write'

from uuid import uuid4
from aiofcm import FCM, Message, PRIORITY_HIGH


async def run():
    fcm = FCM('<NUMERICAL_SENDER_ID>', '<API_KEY>')
    message = Message(
        device_token='<DEVICE_TOKEN>',
        notification={           # optional
            "title": "Hello from Firebase",
            "body": "This is notification",
            "sound": "default"
        },
        data={"score": "3x1"},   # optional
        message_id=str(uuid4())  # optional
        time_to_live=3,          # optional
        priority=PRIORITY_HIGH,  # optional
    )
    await fcm.send_message(message)

loop = asyncio.get_event_loop()
loop.run_until_complete(run())
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/aioopenssl/__init__.py", line 319, in _tls_do_handshake
    self._tls_conn.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/OpenSSL/SSL.py", line 1716, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/OpenSSL/SSL.py", line 1456, in _raise_ssl_error
    _raise_current_error()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
'XMLStream' object has no attribute '_writer'

Is there any way to solve this issue or is it a BUG ?

OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

I run test code which is offered in README with my sender_id, api_key and device token.

However, the below exception happens.

[('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
Traceback (most recent call last):
  File "/Users/sangminkim/Library/Python/3.6/lib/python/site-packages/aioopenssl/__init__.py", line 331, in _tls_do_handshake
    self._tls_conn.do_handshake()
  File "/Users/sangminkim/Library/Python/3.6/lib/python/site-packages/OpenSSL/SSL.py", line 1907, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "/Users/sangminkim/Library/Python/3.6/lib/python/site-packages/OpenSSL/SSL.py", line 1639, in _raise_ssl_error
    _raise_current_error()
  File "/Users/sangminkim/Library/Python/3.6/lib/python/site-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
invalid state
Traceback (most recent call last):
  File "/Users/sangminkim/Library/Python/3.6/lib/python/site-packages/aioopenssl/__init__.py", line 331, in _tls_do_handshake
    self._tls_conn.do_handshake()
  File "/Users/sangminkim/Library/Python/3.6/lib/python/site-packages/OpenSSL/SSL.py", line 1907, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "/Users/sangminkim/Library/Python/3.6/lib/python/site-packages/OpenSSL/SSL.py", line 1639, in _raise_ssl_error
    _raise_current_error()
  File "/Users/sangminkim/Library/Python/3.6/lib/python/site-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/Users/sangminkim/Library/Python/3.6/lib/python/site-packages/aioopenssl/__init__.py", line 346, in _tls_do_handshake
    self._waiter.set_exception(exc)
asyncio.base_futures.InvalidStateError: invalid state
from uuid import uuid4
from aiofcm import FCM, Message, PRIORITY_HIGH


async def run():
    fcm = FCM('<NUMERICAL_SENDER_ID>', '<API_KEY>')
    message = Message(
        device_token='<DEVICE_TOKEN>',
        notification={           # optional
            "title": "Hello from Firebase",
            "body": "This is notification",
            "sound": "default"
        },
        data={"score": "3x1"},   # optional
        message_id=str(uuid4()),  # optional
        time_to_live=3,          # optional
        priority=PRIORITY_HIGH,  # optional
    )
    await fcm.send_message(message)

loop = asyncio.get_event_loop()
loop.run_until_complete(run())

python3.6.5
aioapns==1.4
aiofcm==1.1.0
aiohttp==3.3.2
aioopenssl==0.4.0
aiosasl==0.3.1
aioxmpp==0.9.0

Feature request: Send to firebase Topic

I think this quite simple but also good library is missing just 'send to topic' implementation.
Something simple like this could work:

result = dict(
            message_id=self.message_id,
            to=self.device_token or  '/topics/{0}'.format(self.topic_name),
        )

Of course, current implementation allows reusing device_token and just sending the /topics with it, but this way will be more simple

VAPID Implementation

Not exactly an issue, but wanted to know if you had any plans to implement an async version of Web Push / VAPID?

OpenSSL.SSL.Error

Hi! I try run example code, and get follow traceback (Python 3.5.6 on windows7 and debian8):

Fatal error on tls handshake
protocol: <aioxmpp.protocol.XMLStream object at 0x2b1a054c0320>
transport: <aioopenssl.STARTTLSTransport object at 0x2b1a054c0860>
Traceback (most recent call last):
  File "/home/dev/.pyenv/versions/aiofcm_test/lib/python3.5/site-packages/aioopenssl/__init__.py", line 331, in _tls_do_handshake
    self._tls_conn.do_handshake()
  File "/home/dev/.pyenv/versions/aiofcm_test/lib/python3.5/site-packages/OpenSSL/SSL.py", line 1915, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "/home/dev/.pyenv/versions/aiofcm_test/lib/python3.5/site-packages/OpenSSL/SSL.py", line 1647, in _raise_ssl_error
    _raise_current_error()
  File "/home/dev/.pyenv/versions/aiofcm_test/lib/python3.5/site-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
Exception in callback <bound method STARTTLSTransport._tls_do_handshake of <aioopenssl.STARTTLSTransport object at 0x2b1a054c0860>>
handle: <Handle cancelled>
Traceback (most recent call last):
  File "/home/dev/.pyenv/versions/aiofcm_test/lib/python3.5/site-packages/aioopenssl/__init__.py", line 331, in _tls_do_handshake
    self._tls_conn.do_handshake()
  File "/home/dev/.pyenv/versions/aiofcm_test/lib/python3.5/site-packages/OpenSSL/SSL.py", line 1915, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "/home/dev/.pyenv/versions/aiofcm_test/lib/python3.5/site-packages/OpenSSL/SSL.py", line 1647, in _raise_ssl_error
    _raise_current_error()
  File "/home/dev/.pyenv/versions/aiofcm_test/lib/python3.5/site-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "uvloop/cbhandles.pyx", line 66, in uvloop.loop.Handle._run
  File "/home/dev/.pyenv/versions/aiofcm_test/lib/python3.5/site-packages/aioopenssl/__init__.py", line 346, in _tls_do_handshake
    self._waiter.set_exception(exc)
  File "/home/dev/.pyenv/versions/3.5.6/lib/python3.5/asyncio/futures.py", line 361, in set_exception
    raise InvalidStateError('{}: {!r}'.format(self._state, self))
asyncio.futures.InvalidStateError: FINISHED: <Future finished exception=ConnectionError('_force_close() called',)>

OpenSSL.SSL.SysCallError: (-1, 'Unexpected EOF')

I am using the module to send messages from aiohttp application and it works, but there is something strange. After each message send I get the following exception:

DEBUG:aiofcm:Closing connection <aiofcm.connection.FCMXMPPConnection object at 0x105179b70>
WARNING:aiofcm:Stream of <aiofcm.connection.FCMXMPPConnection object at 0x105179b70> destroyed:
DEBUG:aiofcm:Connection <aiofcm.connection.FCMXMPPConnection object at 0x105179b70> discarded
INFO:aiofcm:Connection released (total: 0)
ERROR:asyncio:Fatal read error on STARTTLS transport
protocol: <aioxmpp.protocol.XMLStream object at 0x10517f748>
transport: <aioopenssl.STARTTLSTransport object at 0x10517f7b8>
Traceback (most recent call last):
  File "/Users/zaro/dev/civilcourage-backend/.direnv/python-3.6.1/lib/python3.6/site-packages/aioopenssl/__init__.py", line 444, in _read_ready
    data = self._sock.recv(self.MAX_SIZE)
  File "/Users/zaro/dev/civilcourage-backend/.direnv/python-3.6.1/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1516, in recv
    self._raise_ssl_error(self._ssl, result)
  File "/Users/zaro/dev/civilcourage-backend/.direnv/python-3.6.1/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1371, in _raise_ssl_error
    raise SysCallError(-1, "Unexpected EOF")
OpenSSL.SSL.SysCallError: (-1, 'Unexpected EOF')

The message is send and received successfully, and everything works as expected. But still this seems strange effect.

I installed the latest available version from pip. Here the versions of aiohttp packages I have:

  • aiofcm (0.4)
  • aiohttp (2.0.7)
  • aioopenssl (0.3.1)

FCM.pool.MAX_ATTEMPTS

Hi,
Is the var FCM.pool.MAX_ATTEMPTS usable?
I want to reduce attempts to 1 how can I do this?

Could not connect to server

I have used Basic Usage code to test FCM notifications for Android.

I have filed API key and device token and also changed sender_id. However, when I run the example, I got:

Could not connect to server:
Could not send notification A-B-C-D-E due to connection problem

There is no exception or message what failed after Could not connect to server.
I have also tried to change port to FCMXMPPConnection.FCM_PORT = 5236 (which should be some testing port), but the outcome remains the same.

I am using Firebase Cloud Messaging API (V1)

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.