I am using PyAPNS to connect to APNs from Python. When running as a stand alone script, all is working fine and push messages get delivered. When running in the Google App Engine Development environment, I get the following error:
Traceback (most recent call last):
File "/usr/local/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "/usr/local/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "/usr/local/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "/usr/local/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1102, in __call__
return handler.dispatch()
File "/usr/local/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "/usr/local/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/mnt/dev/OmegaHandler.py", line 173, in apns
apns.gateway_server.send_notification("70f23022d76aae0176844087c97f0ff068dd3e3686dbac086b8f82a630d0196a", payload)
File "/mnt/dev/apns.py", line 544, in send_notification
self.write(self._get_notification(token_hex, payload))
File "/mnt/dev/apns.py", line 273, in write
return self._connection().write(string)
File "/mnt/dev/apns.py", line 254, in _connection
self._connect()
File "/mnt/dev/apns.py", line 230, in _connect
self._ssl = wrap_socket(self._socket, self.key_file, self.cert_file)
File "/usr/local/lib/python2.7/ssl.py", line 911, in wrap_socket
ciphers=ciphers)
File "/usr/local/lib/python2.7/ssl.py", line 535, in __init__
if sock.getsockopt(SOL_SOCKET, SO_TYPE) != SOCK_STREAM:
File "/mnt/dev/rsocket.py", line 225, in meth
return getattr(self._sock,name)(*args)
error: [Errno 22] Invalid argument
I used this answer to help the "Permission denied" error in the development environment. Again, when running stand alone, all is working fine using the exact same library and code. The error seems to come from getsockopt
being called with options (1, 3)
. I have no clue anymore.
Why is this occurring in the development environment, monkey patched with the stock Python socket.py and not occurring in a stand alone script. Please do not answer that I need to enable billing in order to use the Socket API, this is only happening in the development environment. Thanks.
Edit: This is also happening on a different machine and with a different server (regular SSL socket connection to some server outside the Google IP address range).