dcai / airnotifier

Push Notifications Server for Human Beings.
Other
593 stars 187 forks source link

Error 500 object has no attribute 'encode' #225

Open maudrid opened 3 years ago

maudrid commented 3 years ago

:question: Question

AirNotifier 2.x

Hi there. I'm getting an error when using the push API. The message is still pushed and arrives at the destination, but the API Response is 500. Here is a debug log:

2020-11-30 15:28:47,306 - DEBUG - AirNotify POST URL: http://airnotifier:8801/api/v2/push
2020-11-30 15:28:47,307 - DEBUG - AirNotify Payload: {'device': 'fcm', 'token': 'my registered token', 'alert': 'My Message', 'badge': 1}
2020-11-30 15:28:47,641 - WARNING - Failed to send AirNotify notification: Internal server error., error=500.
2020-11-30 15:28:47,641 - DEBUG - Response Details:
b'{"error": "\'bytes\' object has no attribute \'encode\'"}'

Any idea what this may be?

SavvyEngineer commented 3 years ago

same here @maudrid did you find any solution?

SavvyEngineer commented 3 years ago
[I 210626 20:14:56 dao:25] find token: fduxKoZZRiSp39kCYLHNKz:APA91bFv-C88mkeQyQvLC92UyGuvnalXj3F4K_i7oJPx1h5It6EelKs-1fhnHCd1zGlG07Zy_5wJs5x_rWk7hHe37SV-ZAvMUroTzpSB5GgHbsR4t4TCP9vLgA2P-_Q7-Xf5Q0Pnzqf-
[I 210626 20:14:56 push:111] sending notification to fcm: fduxKoZZRiSp39kCYLHNKz:APA91bFv-C88mkeQyQvLC92UyGuvnalXj3F4K_i7oJPx1h5It6EelKs-1fhnHCd1zGlG07Zy_5wJs5x_rWk7hHe37SV-ZAvMUroTzpSB5GgHbsR4t4TCP9vLgA2P-_Q7-Xf5Q0Pnzqf-
[E 210626 20:14:56 push:177] Traceback (most recent call last):
      File "/root/airnotifier/api/push.py", line 116, in post
        fcmconn = self.fcmconnections[self.app["shortname"]][0]
    IndexError: list index out of range

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "/root/airnotifier/api/push.py", line 119, in post
        statuscode = ex.code
    AttributeError: 'IndexError' object has no attribute 'code'
     'IndexError' object has no attribute 'code'
[E 210626 20:14:56 web:2242] 500 POST /api/v2/push (178.173.152.3) 16.97ms
[I 210626 20:14:56 __init__:217] PushHandler call ends 0.016781330108642578
maudrid commented 3 years ago

Hi @SavvyEngineer

This was quite some time ago and if I recall I was able to get around the issue, but I really dont remember how.You are on the right track with the index error. It has to do with the app name. On my PC I see my files are on branch 2.x, I'm using docker compose to start it. I have 1 successful app added.

desktop:~/work/airnotifier$ docker-compose ps
   Name                  Command               State            Ports

-------------------------------------------------------------------------------
airnotifier   /bin/sh -c /airnotifier/st ...   Up      0.0.0.0:8801->8801/tcp

mongodb       docker-entrypoint.sh mongo ...   Up      0.0.0.0:27017
->27017/tcp
desktop:~/work/airnotifier$ git status
On branch 2.x
Your branch is up to date with 'origin/2.x'.

On Sat, Jun 26, 2021 at 10:16 PM SavvyEngineer @.***> wrote:

[I 210626 20:14:56 dao:25] find token: fduxKoZZRiSp39kCYLHNKz:APA91bFv-C88mkeQyQvLC92UyGuvnalXj3F4K_i7oJPx1h5It6EelKs-1fhnHCd1zGlG07Zy_5wJs5x_rWk7hHe37SV-ZAvMUroTzpSB5GgHbsR4t4TCP9vLgA2P-_Q7-Xf5Q0Pnzqf- [I 210626 20:14:56 push:111] sending notification to fcm: fduxKoZZRiSp39kCYLHNKz:APA91bFv-C88mkeQyQvLC92UyGuvnalXj3F4K_i7oJPx1h5It6EelKs-1fhnHCd1zGlG07Zy_5wJs5x_rWk7hHe37SV-ZAvMUroTzpSB5GgHbsR4t4TCP9vLgA2P-_Q7-Xf5Q0Pnzqf- [E 210626 20:14:56 push:177] Traceback (most recent call last): File "/root/airnotifier/api/push.py", line 116, in post fcmconn = self.fcmconnections[self.app["shortname"]][0] IndexError: list index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/airnotifier/api/push.py", line 119, in post statuscode = ex.code AttributeError: 'IndexError' object has no attribute 'code' 'IndexError' object has no attribute 'code'

[E 210626 20:14:56 web:2242] 500 POST /api/v2/push (178.173.152.3) 16.97ms [I 210626 20:14:56 init:217] PushHandler call ends 0.016781330108642578

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/airnotifier/airnotifier/issues/225#issuecomment-869056672, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACJQ64ZW5J5QKERMA34TTTLTUYYQVANCNFSM4UHXQLRA .

SavvyEngineer commented 3 years ago

@maudrid thanks for the reply I found out that I was using my firebase server key in Firebase Cloud Messaging settings and it was wrong then I looked back in the Docs of Installation 3.x and I found out that I had to do it this way Get the json key file from "Project settings" => "Service accounts", then generate the private key, download the json file, and copy paste content to airnotifier FCM settings.