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

Invalid registration_id on apns #679

Open
As226 opened this issue May 3, 2023 · 1 comment
Open

Invalid registration_id on apns #679

As226 opened this issue May 3, 2023 · 1 comment

Comments

@As226
Copy link

As226 commented May 3, 2023

I submit my problem to you hoping to have a solution.
I use an ios application whose admin part is built in django/python.
Everything was working fine until mid 2022, we encountered a problem with the expired certificate, this certificate has been renewed but since then when you install the app on an iPad it's going well but when you connect (id + password password) things don't go as planned. The app remains blocked and the server side logs record the message below:

`[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_in (data-HEAP): POST /api/apns/update/ HTTP/1.1\r\n
[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_in [getline-blocking] 0 readbytes
[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_in (data-HEAP): 34 bytes
[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_in (data-HEAP): Host: django.example.com\r\n

[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_in (data-HEAP): {"registration_id":"{length=32,bytes=0x5124a3ee7b3a9b3afa63db66c63df4b8...0a5253c7e9fc0144}"}
[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_out
[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_out (data-HEAP): 258 bytes
[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_out (data-HEAP): HTTP/1.1 400 Bad Request\r\nDate: Thu, 23 apr 2023 09:46:27 GMT\r\nServer: Apache/2.4.6 (CentOS) mod_wsgi/3.4 Python/2.7.5\r\nVary: Accept\r\nX-Frame-Options: SAMEORIGIN\r\nAllow: POST, OPTIONS\r\nContent-Length: 37\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n
[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_out
[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_out (data-HEAP): 37 bytes
[dumpio:trace7] [pid 10033] mod_dumpio.c(103): [client ] mod_dumpio:  dumpio_out (data-HEAP): {"message":"Invalid registration_id"}`

I'm trying to figure out where the problem is coming from. Old ipad ipads work correctly, the problem only occurs after new tablets (if you reinstall on an old tablet no problem, but if new tablet or reset problem).

I'm thinking of a certificate problem, I created a new one but the problem persists. Is the problem with django push notification? I don't know but at this point I have a thousand and one questions, I'm stuck and I need your help.

`@api_view(['POST',])
@parser_classes((JSONParser,))
def createAPNSDevice(request):
    try:
        device = APNSDevice.objects.get(registration_id=request.data["registration_id"])
    except:
        apns = APNSDeviceSerializer(data=request.data)
        if not apns.is_valid(raise_exception=True):
            return Response({"message": "Invalid data",}, status=400)
        apns.save()
    return Response({"message": "APNS device created",}, status=200)


@api_view(['POST',])
@authentication_classes([TokenAuthentication,])
@parser_classes((JSONParser,))
def updateAPNSDevice(request):
    try:
        apns = APNSDevice.objects.get(registration_id=request.data["registration_id"])
        apns.user = request.user
        apns.save()
    except:
        return Response({"message": "Invalid registration_id", }, status=400)
    return Response({"message": "APNS device updated",}, status=200)`
`# -*- coding: utf-8 -*-
"""
Django settings for inspectionsBO project.

Generated by 'django-admin startproject' using Django 1.8.3.

For more information on this file, see
https://docs.djangoproject.com/en/1.8/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.8/ref/settings/
"""

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


SECRET_KEY = 'something'

DEBUG = True

ALLOWED_HOSTS = ["django.example.com"]


INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'core',
    'rest_framework.authtoken',
    'admin_reorder',
    'push_notifications',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
    'admin_reorder.middleware.ModelAdminReorder',
)

ROOT_URLCONF = 'example.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'example.wsgi.application'


DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'dbname',
        'USER': 'username',
        'PASSWORD': 'passwrd',
        'HOST': '',
        'PORT': '',
    }
}


LANGUAGE_CODE = 'en-EN'


BASE_SERVER_URL = 'http://django.example.com'
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "static/images/")
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
IMAGES_ROOT = os.path.join(BASE_DIR, "static/images/")
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "static/"),
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_PARSER_CLASSES': (
    'rest_framework.parsers.JSONParser',
    'rest_framework.parsers.FormParser',
    'rest_framework.parsers.MultiPartParser',
    ),
}


EMAIL_USE_TLS = False
EMAIL_HOST = 'ip adress'
EMAIL_HOST_USER = 'xxxxxxx'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'simple': {
            'format': '%(asctime)s %(levelname)s %(name)s %(message)s'
        },
    },
    'handlers': {
        'default': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': BASE_DIR + '/Log/info.log',
            'maxBytes': 1024*1024*5,
            'backupCount': 5,
            'formatter':'simple',
        },
        'import': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': BASE_DIR + '/Log/import.log',
            'maxBytes': 1024 * 1024 * 5,
            'backupCount': 5,
            'formatter': 'simple',
        },
    },
    'root': {
        'handlers': ['default'],
        'level': 'DEBUG'
    },
    'loggers': {
        'sample': {
            'handlers': ['default'],
            'level': 'ERROR',
            'propagate': True,
        },
        'import': {
            'handlers': ['import'],
            'level': 'DEBUG',
            'propagate': True,
        },
    }
}

PUSH_NOTIFICATIONS_SETTINGS = {
        "APNS_CERTIFICATE": os.path.join(BASE_DIR, "static/apns-prod-cert.pem"),
        "APNS_HOST": "gateway.push.apple.com",
        "APNS_FEEDBACK_HOST": "feedback.push.apple.com",
}`

Thank you

@jamaalscarlett
Copy link
Member

@As226 When are you seeing this error, when you login? When you attempt to send a notification?

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

No branches or pull requests

2 participants