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

Push not being recieved by devices anymore #111

Closed
gregorskii opened this issue Feb 20, 2015 · 9 comments
Closed

Push not being recieved by devices anymore #111

gregorskii opened this issue Feb 20, 2015 · 9 comments

Comments

@gregorskii
Copy link

Hi there,

We are using this plugin on Google App Engine with a Cloud Endpoints project.

Several months back when we were testing the integration the push messages were sending.

We have not made any major modifications to our push code and now the messages are not sending.

The App Engine logs show:

GatewayConnection APNS connection establishing...
GatewayConnection APNS connection established
GatewayConnection APNS connection closed

and does not report any 500 errors or SSL/key errors. But the message is not received by the phone.

We are also getting "Deadline Exceeded Errors" at least one of the times we tried.

Our keys are signed correctly using this process:

in keychain access, select both cert and key then export to Certificates.p12 file.

to generate cert.pem
openssl pkcs12 -in Certificates.p12 -out cert.pem -nodes -nokeys

to generate key.pem
openssl pkcs12 -in Certificates.p12 -out key.pem -nodes -nocerts

Our push code is copied directly from the instructions:


def send_single_push(u, payload):

    apns = get_apns_handler(False)

    # Send multiple notifications in a single transmission
    frame = Frame()
    identifier = 1
    expiry = time.time()+3600
    priority = 10

    pa = PushAlias.query(PushAlias.user == u.key).fetch(1)

    if pa:
        pa = pa[0]

    bc = PushBadgeCount.query(PushBadgeCount.alias == pa.key).fetch(1)

    if bc:
        bc = bc[0]

    # Increase the badge count
    bc.badge_count += 1
    bc.put()

    # Set the payload data and badge count
    apns_payload = Payload(
        alert=payload['alert'],
        sound=payload['sound'] if payload.has_key('sound') and payload['sound'] else "default",
        badge=bc.badge_count
    )

    # Add a push to the frame for each device in the alias
    for device in pa.devices:
        frame.add_item(device, apns_payload, identifier, expiry, priority)

    if get_environment() != 'sandbox':
        try:
            apns.gateway_server.send_notification_multiple(frame)
        except:
            # Force re-connect
            apns.gateway_server._connect()

        return False, None

We are mimicking Urban Airship like functionality.

And the keys are set as such:


def get_apns_handler(enhanced=False):

    sandbox = True
    cert = APNS_CERT_SANDBOX
    pem = APNS_PEM_SANDBOX

    # if get_environment() == 'prod':
    #     sandbox = False
    #     cert = APNS_CERT_PRODUCTION
    #     pem = APNS_PEM_PRODUCTION

    return APNs(use_sandbox=sandbox, cert_file=cert, key_file=pem, enhanced=enhanced)

We are using Googles own SSL library via the app.yaml:


libraries:
    - name: ssl
      version: latest

Any help would be greatly appreciated. Let me know if you need more information.

@CTassisF
Copy link

Hey,

I'm currently using PyAPNs in a GAE project and I am not seeing any errors.

A few advices:

  • It will only work on "python27" runtime;
  • You need to have billing enabled in your project in order to use sockets API;
  • Remember to load "ssl" library (you're already doing that);
  • Put your plain text certificates hard coded and load them using StringIO.StringIO(cert_var);

If you're still seeing problems check if you're not sending messages to sandboxed tokens without "use_sandbox = True" (or vice versa).

@gregorskii
Copy link
Author

Thanks @CTassisF

  • We are using the python27 runtime
  • We do have billing enabled
  • We are loading the SSL library as noted above
  • We tried using both the sandbox and the prod certs

We are loading the certificates like this and it worked previously:


##
# APNS
##

APNS_CERT_SANDBOX = os.path.join(os.path.dirname(__file__), 'apns_keys/development_cert.pem')
APNS_PEM_SANDBOX = os.path.join(os.path.dirname(__file__), 'apns_keys/development_key.pem')
APNS_CERT_PRODUCTION = os.path.join(os.path.dirname(__file__), 'apns_keys/production_key.pem')
APNS_PEM_PRODUCTION = os.path.join(os.path.dirname(__file__), 'apns_keys/production_key.pem')


And we are not getting any SSL errors with the certs.

@CTassisF
Copy link

@gregorskii
I had a few problems loading certificates from files when I started using PyAPNs on GAE and that's why I'm using StringIO.StringIO().
I'm also not using the latest PyAPNs version available (v2.0.1), I'm using v2.0 because of #108.
This is the log when my push'es are sent:

D 2015-02-20 19:23:40.333 GatewayConnection APNS connection establishing...
D 2015-02-20 19:23:40.618 GatewayConnection APNS connection established
I 2015-02-20 19:23:40.627 GatewayConnection APNS connection closed

Your log matches mine.
I can't think anything but wrong token/sandbox combinations or problems with certificate loading.

@gregorskii
Copy link
Author

I believe I am using the most current version, however the files do not denote the version anywhere that I can see.

I am pulling from https://github.com/djacobs/PyAPNs.git I do not remember specifically the last time I reran pip install -r from my requirements file. But I believe it was recently. I can try that again.

If the certificate did not load wouldn't the call to APNS throw a SSL connection error? When we were messing with the certs last night and had it setup wrong it was indeed throwing an error which resulted in a 500 error to our front end.

I will try rebuilding my package requirements, but its good that someone else is using this plugin on App Engine and having success, we must just have a config issue somewhere.

If you or anyone else has any other suggestions we would greatly appreciate it.

Thanks!

@gregorskii
Copy link
Author

I tried updating the modules via pip install -r from my requirements file. I also tried using StringIO.StringIO to read the cert files. Neither worked.

I am still at a loss for how to fix this.

Does anyone know of any other debugging techniques to get more detail into what is happening?

Thanks

@FredrikL
Copy link

If it helps I had the same problem, turned out my cert file was wrong.

@gregorskii
Copy link
Author

Would you mind adding the instructions you used to create the key and load it in app engine? The ones I used are above.

I would really appreciate it.

@gregorskii
Copy link
Author

I changed enhanced mode to True and the pushes started sending. Can anyone explain why enhanced False and enhanced True would cause this to happen?

@gregorskii
Copy link
Author

Resolved by using enhanced=True

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

3 participants