I'm trying to set up tests in my Flask but for an unknown reason, Flask fails when I add a parameter with arobase.
I followed the snippet here http://flask.pocoo.org/snippets/26/ and can make a successful request (it works), but when I try to do a post, it fails (with the following exception) :
def test_auth_login_fail(self):
""" Login fail """
result = self.client.post(self._make_url("/auth/login"), data=dict(
email="user#website.com",
password='cxcxz'
))
self.assertEqual(result.status_code, 404)
And the exception :
Traceback (most recent call last):
File "/var/www/html/api/apps/auth/tests/login.py", line 20, in test_auth_login_fail
password='cxcxz'
File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 772, in post
return self.open(*args, **kw)
File "/usr/lib/python2.7/site-packages/flask/testing.py", line 108, in open
follow_redirects=follow_redirects)
File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 736, in open
response = self.run_wsgi_app(environ, buffered=buffered)
File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 659, in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 855, in run_wsgi_app
app_iter = app(environ, start_response)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/var/www/html/api/utils/middlewares.py", line 55, in __call__
return self.app(environ, start_response)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "/usr/lib/python2.7/site-packages/flask/app.py", line 1577, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "/usr/lib/python2.7/site-packages/werkzeug/wrappers.py", line 827, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "/usr/lib/python2.7/site-packages/werkzeug/wrappers.py", line 57, in _run_wsgi_app
return _run_wsgi_app(*args)
File "/usr/lib/python2.7/site-packages/werkzeug/test.py", line 855, in run_wsgi_app
app_iter = app(environ, start_response)
TypeError: 'tuple' object is not callable
For informations, this doesn't generate an exception :
def test_auth_login_fail(self):
""" Login fail """
result = self.client.post(self._make_url("/auth/login"), data=dict(
email="userwebsite.com",
password='cxcxz'
))
self.assertEqual(result.status_code, 404)
(notice the "#" removed)
I also removed the Middleware (indicated in the traceback) without much success.
What am I missing ?
Looks like in case of an email is correct, you return something wrong (a tuple) from your view function. And when you pass a malformed email, the value you return is ok.
Related
I have a project here that is a working signed-url S3 uploader (on real S3.) On localstack, I get 500 error, and logs show this when I try to upload a file:
2020-09-24 11:01:46,055:API: Error on request:
Traceback (most recent call last):
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 323, in run_wsgi
execute(self.server.app)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/werkzeug/serving.py", line 312, in execute
application_iter = app(environ, start_response)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/server.py", line 167, in __call__
return backend_app(environ, start_response)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2464, in __call__
return self.wsgi_app(environ, start_response)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2450, in wsgi_app
response = self.handle_exception(e)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1867, in handle_exception
reraise(exc_type, exc_value, tb)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/core/utils.py", line 146, in __call__
result = self.callback(request, request.url, {})
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/s3/responses.py", line 237, in ambiguous_response
return self.bucket_response(request, full_url, headers)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/s3/responses.py", line 246, in bucket_response
response = self._bucket_response(request, full_url, headers)
File "/opt/code/localstack/.venv/lib/python3.8/site-packages/moto/s3/responses.py", line 284, in _bucket_response
body = body.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
What do I need to do to make it work, as it does on real S3?
I'll answer my own question. it was localstack/issues#1410. My example now works.
The short of it is add s3ForcePathStyle: true to options, so it correctly generates signed-URL
I'm trying to deploy my telegram-bot on PythonAnywhere. It has worked fine with the free account but there are some troubles with the paid one. I'm getting "OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_record', 'decryption failed or bad record mac')]" messages in Error logs (accordingly bot works wrong). How can I solve it?
I'm using python3.7 + pyTelegramBotAPI + flask
Code example for error reproducing:
# coding=utf-8
import telebot
import flask
import time
token = 'bot_token'
bot = telebot.TeleBot(token, threaded=False)
WEBHOOK_HOST = '*userName*.pythonanywhere.com'
WEBHOOK_URL_BASE = "https://%s" % (WEBHOOK_HOST)
WEBHOOK_URL_PATH = "/%s/" % (token)
app = flask.Flask(__name__)
# Process webhook calls
#app.route(WEBHOOK_URL_PATH, methods=['POST'])
def webhook():
if flask.request.headers.get('content-type') == 'application/json':
json_string = flask.request.get_data().decode('utf-8')
update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update])
return ''
else:
flask.abort(403)
#bot.message_handler(commands=['start', 'help'])
def handle_start_help(message):
bot.send_message(message.chat.id, text="Hello, my friend")
bot.remove_webhook()
time.sleep(0.1)
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH)
Full error trace:
2018-10-30 12:40:33,351: Exception on /*token*/ [POST]
Traceback (most recent call last):
File "/usr/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/kleratoni/bot/bot/Main.py", line 90, in webhook
bot.process_new_updates([update])
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 326, in process_new_updates
self.process_new_callback_query(new_callback_querys)
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 354, in process_new_callback_query
self._notify_command_handlers(self.callback_query_handlers, new_callback_querys)
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 1490, in _notify_command_handlers
self._exec_task(message_handler['function'], message)
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 464, in _exec_task
task(*args, **kwargs)
File "/home/*accountName*/bot/bot/Main.py", line 535, in callback_inline
MainMenuActions.BetMenu_BackButton(call.message, bot, db)
File "/home/*accountName*/bot/bot/MainMenuActions.py", line 130, in BetMenu_BackButton
bot.send_message(message.chat.id, text=config.StringContent["StartPlayWords"], reply_markup=keyborads.keyboardMainmenu)
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/__init__.py", line 598, in send_message
reply_markup, parse_mode, disable_notification))
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/apihelper.py", line 140, in send_message
return _make_request(token, method_url, params=payload, method='post')
File "/home/*accountName*/.local/lib/python3.7/site-packages/telebot/apihelper.py", line 54, in _make_request
timeout=(connect_timeout, read_timeout), proxies=proxy)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 512, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3.7/site-packages/requests/sessions.py", line 622, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3.7/site-packages/requests/adapters.py", line 445, in send
timeout=timeout
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 600, in urlopen
chunked=chunked)
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "<string>", line 2, in raise_from
File "/usr/lib/python3.7/site-packages/urllib3/connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "/usr/lib/python3.7/http/client.py", line 1321, in getresponse
response.begin()
File "/usr/lib/python3.7/http/client.py", line 296, in begin
version, status, reason = self._read_status()
File "/usr/lib/python3.7/http/client.py", line 257, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/usr/lib/python3.7/socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "/usr/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 300, in recv_into
return self.recv_into(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 285, in recv_into
return self.connection.recv_into(*args, **kwargs)
File "/usr/lib/python3.7/site-packages/OpenSSL/SSL.py", line 1814, in recv_into
self._raise_ssl_error(self._ssl, result)
File "/usr/lib/python3.7/site-packages/OpenSSL/SSL.py", line 1639, in _raise_ssl_error
_raise_current_error()
File "/usr/lib/python3.7/site-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'ssl3_get_record', 'decryption failed or bad record mac')]
From an issue on the pyTelegramBotAPI github repo, it looks like it's an incompatibility between the version of requests you're using and the version of OpenSSL you're using. Try using requests 2.10.0 instead.
I had a same error and I fixed like this
token = 'bot_token'
bot = telebot.TeleBot(token, threaded=False)
I am trying to debug a view in my Flask app that is return a 500 status with the error TypeError: 'bool' object is not callable in the traceback. The view calls login_user from Flask-Login then returns True to indicate that the login was successful.
I have debugged until app_iter = app(environ, start_response) and the app is now a boolean with the value True rather than the Flask app object.
Traceback (most recent call last):
File "D:\Python27\lib\site-packages\flask\app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "D:\Python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "D:\Python27\lib\site-packages\flask\app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "D:\Python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "D:\Python27\lib\site-packages\flask\app.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "D:\Python27\lib\site-packages\flask\app.py", line 1577, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "D:\Python27\lib\site-packages\werkzeug\wrappers.py", line 824, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "D:\Python27\lib\site-packages\werkzeug\wrappers.py", line 57, in _run_wsgi_app
return _run_wsgi_app(*args)
File "D:\Python27\lib\site-packages\werkzeug\test.py", line 854, in run_wsgi_app
app_iter = app(environ, start_response)
TypeError: 'bool' object is not callable
#app.route('/login', methods=['POST'])
def login():
username = request.form['username']
user = User.query.filter_by(username=username).first()
if user:
login_user(user)
return True
return False
In Flask, a view must return one of the following:
a string
a Response object (or subclass)
a tuple of (string, status, headers) or (string, status)
a valid WSGI application
Flask tests for the first 3 options, and if they don't fit, assumes it is the fourth. You returned True somewhere, and it is being treated as a WSGI application instead.
See About Responses in the documentation.
My route
#app.route('/oauth2callback')
def oauth2callback():
flow = client.flow_from_clientsecrets(
'client_secrets.json',
scope='https://www.googleapis.com/auth/drive.metadata.readonly',
redirect_uri=flask.url_for('oauth2callback', _external=True),
include_granted_scopes=True)
if 'code' not in flask.request.args:
auth_uri = flow.step1_get_authorize_url()
return flask.redirect(auth_uri)
else:
auth_code = flask.request.args.get('code')
credentials = flow.step2_exchange(auth_code)
flask.session['credentials'] = credential.to_json()
return flask.redirect(flask.url_for('home'))
which when called gives the following exception
ERROR 2016-04-19 11:10:59,804 wsgi.py:279]
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/google/appengine/runtime/wsgi.py", line 267, in Handle
result = handler(dict(self._environ), self._StartResponse)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/vinay/App-Engine/Rainbow/gaenv/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/vinay/App-Engine/Rainbow/mainsite/__init__.py", line 65, in oauth2callback
include_granted_scopes=True)
File "/Users/vinay/App-Engine/Rainbow/gaenv/oauth2client/util.py", line 135, in positional_wrapper
return wrapped(*args, **kwargs)
TypeError: flow_from_clientsecrets() got an unexpected keyword argument 'include_granted_scopes'
INFO 2016-04-19 11:10:59,881 module.py:787] default: "GET /oauth2callback HTTP/1.1" 500 -
At least the current version of the oauth2client library doesn't support this include_granted_scopes argument: http://oauth2client.readthedocs.org/en/latest/source/oauth2client.client.html#oauth2client.client.flow_from_clientsecrets
You might be using some outdated code/documentation, others have reported the same issue before, for example: https://groups.google.com/forum/#!topic/google-api-python-client/zQttW4WMUrg. I see the unsupported argument still present in that referenced doc.
As I gothered while researching the answer the argument seems to have been used for incremental authorisations. That outdated referenced doc actually has an Incremental authorization section which shows:
To avoid this complexity, you can include previously granted scopes in
your authorization requests. For example:
flow = client.flow_from_clientsecrets(...)
flow.params['include_granted_scopes'] = True
I'm trying to use Flask-APNS, previously I check that my ck.pem (cert and key on one file) works on a php server.
But everytime I try to execute:
from apns import APNS
#apns = APNS(app, cert_file='ZivingCert.pem', key_file='ZivingKey.pem',passphrase='mypassphrase')
apns = APNS(app, cert_file='ck.pem', passphrase='mypassphrase')
apns.send_message(tokens=['fad71c0b27416f055bfb1617c8db4e55d1b98b412443e68fba65cfe59748b81a'], alert='hi world', extra={})
I get this error:
WARNING:apnsclient.backends.stdio:Failed to establish socket/SSL connection to ('gateway.sandbox.push.apple.com', 2195)
No handlers could be found for logger "apnsclient.backends.stdio"
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
self.result = application(self.environ, self.start_response)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 263, in error_router
return original_handler(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 260, in error_router
return self.handle_error(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 263, in error_router
return original_handler(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 260, in error_router
return self.handle_error(e)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 431, in wrapper
resp = resource(*args, **kwargs)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_httpauth.py", line 60, in decorated
return f(*args, **kwargs)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/views.py", line 84, in view
return self.dispatch_request(*args, **kwargs)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 521, in dispatch_request
resp = meth(*args, **kwargs)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/scheduler/ws/v1/schedulesapns.py", line 21, in get
apns.send_message(tokens=['fad71c0b27416f055bfb1617c8db4e55d1b98b412443e68fba65cfe59748b81a'], alert='hi world', extra={})
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/scheduler/apns/__init__.py", line 134, in send_message
res = srv.send(message)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/apns.py", line 90, in send
status = self._connection.send(message)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/transport.py", line 255, in send
with self:
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/transport.py", line 228, in __enter__
self._open_connection() # can raise exception, bubblit up to the top
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/transport.py", line 519, in _open_connection
timeout=self.session.connect_timeout
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/__init__.py", line 88, in get_cached_connection
return self.get_new_connection(address, certificate, timeout=timeout)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 378, in get_new_connection
return self.connection_class(address, certificate, timeout=timeout)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 142, in __init__
self._open_connection(timeout)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 153, in _open_connection
self._connect_and_handshake()
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 188, in _connect_and_handshake
self._connection.do_handshake()
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1442, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1180, in _raise_ssl_error
raise SysCallError(-1, "Unexpected EOF")
SysCallError: (-1, 'Unexpected EOF')
I finally fixed thanks to logging messages.
To enable logging:
import logging
logging.basicConfig()
To fix WARNING:apnsclient.backends.stdio:Failed to establish socket/SSL connection to ('gateway.sandbox.push.apple.com', 2195) caused by security issue with SSL version 3.0 the Apple Push Notification server remove support for SSL 3.0 since Wednesday, October 29 of 2014.
def my_callback(key, reason):
print "my_callbaaaaaaack"
print str(key)
print str(reason)
import OpenSSL
OpenSSL.SSL.SSLv3_METHOD = OpenSSL.SSL.TLSv1_METHOD
from apns import APNS
apns = APNS(app, cert_file='ck.pem', passphrase='mypassphrase', failure_callback=my_callback)