Python 2.7.16 Gevent-socketio server throwing errors - python-2.7

I'm currently trying to run some code from an old Github repo, and I'm running it on Python version 2.7.16, the code is ran from a file called server.py which starts a local web server where the app is run, code for that server.py file is as follows:
from gevent import monkey
monkey.patch_socket()
from flask import Flask, request, send_file
from socketio import socketio_manage
from resource import Resource
# Flask routes
app = Flask(__name__)
#app.route('/')
def index():
return send_file('static/index.html')
#app.route("/socket.io/<path:path>")
def run_socketio(path):
socketio_manage(request.environ, {'': Resource})
if __name__ == '__main__':
port_num = 8088
# port_num = 8000
# port_num = 80
print 'Listening on http://localhost:%d' % port_num
app.debug = True
import os
from werkzeug.wsgi import SharedDataMiddleware
app = SharedDataMiddleware(app,
{'/': os.path.join(os.path.dirname(__file__),
'static')})
from socketio.server import SocketIOServer
SocketIOServer(('0.0.0.0', port_num), app,
resource="socket.io", policy_server=False).serve_forever()
I'm able to get the web server started, but when I navigate to the page, this error log gets thrown
Traceback (most recent call last):
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/greenlet.py", line 536, in run
result = self._run(*self.args, **self.kwargs)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/baseserver.py", line 26, in _handle_and_close_when_done
return handle(*args_tuple)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/server.py", line 124, in handle
handler.handle()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 454, in handle
result = self.handle_one_request()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 671, in handle_one_request
self.handle_one_response()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 122, in handle_one_response
return self._do_handshake(handshake_tokens.groupdict())
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 64, in _do_handshake
self.write_smart(data)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 88, in write_smart
self.write_plain_result(data)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 78, in write_plain_result
("Content-Type", "text/plain"),
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 805, in start_response
raise UnicodeError("The value must be a native string", header, value)
UnicodeError: ('The value must be a native string', 'Access-Control-Max-Age', 3600)
Wed Nov 2 17:31:24 2022 <Greenlet at 0x10c9589e0: _handle_and_close_when_done(<bound method SocketIOServer.handle of <SocketIOSe, <bound method SocketIOServer.do_close of <SocketIO, (<socket at 0x10c9505d0 fileno=[Errno 9] Bad file )> failed with UnicodeError
Traceback (most recent call last):
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/greenlet.py", line 536, in run
result = self._run(*self.args, **self.kwargs)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/baseserver.py", line 26, in _handle_and_close_when_done
return handle(*args_tuple)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/server.py", line 124, in handle
handler.handle()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 454, in handle
result = self.handle_one_request()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 671, in handle_one_request
self.handle_one_response()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 122, in handle_one_response
return self._do_handshake(handshake_tokens.groupdict())
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 64, in _do_handshake
self.write_smart(data)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 88, in write_smart
self.write_plain_result(data)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 78, in write_plain_result
("Content-Type", "text/plain"),
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 805, in start_response
raise UnicodeError("The value must be a native string", header, value)
UnicodeError: ('The value must be a native string', 'Access-Control-Max-Age', 3600)
Wed Nov 2 17:31:24 2022 <Greenlet at 0x10c958998: _handle_and_close_when_done(<bound method SocketIOServer.handle of <SocketIOSe, <bound method SocketIOServer.do_close of <SocketIO, (<socket at 0x10c950610 fileno=[Errno 9] Bad file )> failed with UnicodeError
Traceback (most recent call last):
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/greenlet.py", line 536, in run
result = self._run(*self.args, **self.kwargs)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/baseserver.py", line 26, in _handle_and_close_when_done
return handle(*args_tuple)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/server.py", line 124, in handle
handler.handle()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 454, in handle
result = self.handle_one_request()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 671, in handle_one_request
self.handle_one_response()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 122, in handle_one_response
return self._do_handshake(handshake_tokens.groupdict())
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 64, in _do_handshake
self.write_smart(data)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 88, in write_smart
self.write_plain_result(data)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/socketio/handler.py", line 78, in write_plain_result
("Content-Type", "text/plain"),
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 805, in start_response
raise UnicodeError("The value must be a native string", header, value)
UnicodeError: ('The value must be a native string', 'Access-Control-Max-Age', 3600)
Wed Nov 2 17:31:24 2022 <Greenlet at 0x10c958998: _handle_and_close_when_done(<bound method SocketIOServer.handle of <SocketIOSe, <bound method SocketIOServer.do_close of <SocketIO, (<socket at 0x10c950790 fileno=[Errno 9] Bad file )> failed with UnicodeError
Traceback (most recent call last):
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 935, in handle_one_response
self.run_application()
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/gevent/pywsgi.py", line 908, in run_application
self.result = self.application(self.environ, self.start_response)
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/werkzeug/middleware/shared_data.py", line 214, in __call__
real_filename, file_loader = loader(path[len(search_path) :])
File "/Users/chenzuyu/Library/Python/2.7/lib/python/site-packages/werkzeug/middleware/shared_data.py", line 178, in loader
if os.path.isfile(path):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/genericpath.py", line 37, in isfile
st = os.stat(path)
TypeError: coercing to Unicode: need string or buffer, NoneType found
Wed Nov 2 17:31:24 2022 {'REMOTE_PORT': '57507', 'HTTP_HOST': 'localhost:8088', 'REMOTE_ADDR': '127.0.0.1', (hidden keys: 29)} failed with TypeError
127.0.0.1 - - [2022-11-02 17:31:24] "GET //soundfont/asset_pack_basic.json HTTP/1.1" 500 161 0.002105
I'm not at all sure why this is happening, and if anyone has ever seen something like this before, please share what possible solutions I have to get this to work.
My python version is 2.7.16 and my installed package versions are as follows:
altgraph 0.10.2
asn1crypto 0.24.0
backports-abc 0.5
bdist-mpkg 0.5.0
bonjour-py 0.3
certifi 2021.10.8
cffi 1.14.3
click 7.1.2
configparser 4.0.2
contextlib2 0.6.0.post1
cryptography 2.9.2
elasticsearch 7.17.7
enum34 1.1.6
Flask 1.1.4
future 0.17.1
futures 3.4.0
gevent 1.2.2
gevent-socketio 0.3.6
gevent-websocket 0.10.1
greenlet 2.0.0
importlib-metadata 2.1.3
ipaddress 1.0.22
itsdangerous 1.1.0
Jinja2 2.11.3
jsonpickle 2.2.0
macholib 1.5.1
MarkupSafe 1.1.1
matplotlib 1.3.1
modulegraph 0.10.4
music21 4.1.0
nose 1.3.7
numpy 1.16.6
pandas 0.24.2
pathlib2 2.3.7.post1
pip 20.3.4
py2app 0.7.3
pycparser 2.19
pyobjc-core 2.5.1
pyobjc-framework-Accounts 2.5.1
pyobjc-framework-AddressBook 2.5.1
pyobjc-framework-AppleScriptKit 2.5.1
pyobjc-framework-AppleScriptObjC 2.5.1
pyobjc-framework-Automator 2.5.1
pyobjc-framework-CFNetwork 2.5.1
pyobjc-framework-Cocoa 2.5.1
pyobjc-framework-Collaboration 2.5.1
pyobjc-framework-CoreData 2.5.1
pyobjc-framework-CoreLocation 2.5.1
pyobjc-framework-CoreText 2.5.1
pyobjc-framework-DictionaryServices 2.5.1
pyobjc-framework-EventKit 2.5.1
pyobjc-framework-ExceptionHandling 2.5.1
pyobjc-framework-FSEvents 2.5.1
pyobjc-framework-InputMethodKit 2.5.1
pyobjc-framework-InstallerPlugins 2.5.1
pyobjc-framework-InstantMessage 2.5.1
pyobjc-framework-LatentSemanticMapping 2.5.1
pyobjc-framework-LaunchServices 2.5.1
pyobjc-framework-Message 2.5.1
pyobjc-framework-OpenDirectory 2.5.1
pyobjc-framework-PreferencePanes 2.5.1
pyobjc-framework-PubSub 2.5.1
pyobjc-framework-QTKit 2.5.1
pyobjc-framework-Quartz 2.5.1
pyobjc-framework-ScreenSaver 2.5.1
pyobjc-framework-ScriptingBridge 2.5.1
pyobjc-framework-SearchKit 2.5.1
pyobjc-framework-ServiceManagement 2.5.1
pyobjc-framework-Social 2.5.1
pyobjc-framework-SyncServices 2.5.1
pyobjc-framework-SystemConfiguration 2.5.1
pyobjc-framework-WebKit 2.5.1
pyOpenSSL 19.0.0
pyparsing 2.0.1
python-dateutil 2.8.2
pytz 2013.7
scandir 1.10.0
scikit-learn 0.20.4
scipy 1.2.3
setuptools 41.0.1
singledispatch 3.7.0
six 1.12.0
sklearn 0.0
tornado 5.1.1
typing 3.10.0.0
urllib3 1.26.12
Werkzeug 0.16.1
wheel 0.33.1
xattr 0.6.4
zipp 1.2.0
zope.event 4.5.0
zope.interface 5.5.0

Related

Using Python2 and scrapy ImportError: cannot import name suppress

Hi am trying to run a scraper on ubuntu/windows machine .
I have installed scrapy version- Scrapy 1.8.0 on using python2.
I am able create a project, but when I run a scraper this error in shown.
Traceback (most recent call last):
File "/home/ubuntu/.local/bin/scrapy", line 8, in <module>
sys.exit(execute())
File "/home/ubuntu/.local/lib/python2.7/site-packages/scrapy/cmdline.py", line 146, in execute
_run_print_help(parser, _run_command, cmd, args, opts)
File "/home/ubuntu/.local/lib/python2.7/site-packages/scrapy/cmdline.py", line 100, in _run_print_help
func(*a, **kw)
File "/home/ubuntu/.local/lib/python2.7/site-packages/scrapy/cmdline.py", line 154, in _run_command
cmd.run(args, opts)
File "/home/ubuntu/.local/lib/python2.7/site-packages/scrapy/commands/shell.py", line 68, in run
crawler.engine = crawler._create_engine()
File "/home/ubuntu/.local/lib/python2.7/site-packages/scrapy/crawler.py", line 111, in _create_engine
return ExecutionEngine(self, lambda _: self.stop())
File "/home/ubuntu/.local/lib/python2.7/site-packages/scrapy/core/engine.py", line 67, in __init__
self.scheduler_cls = load_object(self.settings['SCHEDULER'])
File "/home/ubuntu/.local/lib/python2.7/site-packages/scrapy/utils/misc.py", line 46, in load_object
mod = import_module(module)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/ubuntu/.local/lib/python2.7/site-packages/scrapy/core/scheduler.py", line 7, in <module>
from queuelib import PriorityQueue
File "/home/ubuntu/.local/lib/python2.7/site-packages/queuelib/__init__.py", line 1, in <module>
from queuelib.queue import FifoDiskQueue, LifoDiskQueue
File "/home/ubuntu/.local/lib/python2.7/site-packages/queuelib/queue.py", line 7, in <module>
from contextlib import suppress
ImportError: cannot import name suppress
can anyone help to solve this issue?
The contextlib.suppress function supports from Python 3.4 but you are using Python 2.7. To solve this problem, upgrade your python version.
If this is useful for someone else, the solution for me (also using python 2.7) was:
pip uninstall attrs
pip uninstall queuelib
pip install queuelib==1.5.0
pip install attrs

CERTIFICATE_VERIFY_FAILED in urllib2 but not requests, on Python 2.7.18

My longstanding Python 2.7.17 environment got corrupted, and so I installed Python 2.7.18 using the macOS 64-bit installer downloadable from python.org. Now I get errors when loading HTTPS sites using urllib2 but not requests.
Here is the environment, running macOS Mojave:
Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 19 2020, 20:48:48)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Works fine with requests:
>>> import requests
>>> url='https://github.com'
>>> requests.get(url)
<Response [200]>
Fails with urllib2:
>>> import urllib2
>>> urllib2.urlopen(url)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 429, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 447, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1241, in https_open
context=self._context)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 1198, in do_open
raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>
This occurs in both the plain 2.7.18 I installed and in virtual environments created from it. The problem is bigger than just urllib2, as certain database modules fail, too, that do not use urllib2. Moving to Python3 is not currently an option.
I tried pip install --upgrade certifi but that did not help.
Per [1] monkey-patching fixes the problem, but that is not a viable solution because this is destined to be production code.
Per [1] explicitly setting a non-verifying SSL context sometimes works, but again, it is not viable, plus it fails in certain third-party database interface code.
The answer may be in PEPP [2] or PEPP 493 [3], but the sun will swallow the earth before I understand those.
[1] urllib and "SSL: CERTIFICATE_VERIFY_FAILED" Error
[2] https://www.python.org/dev/peps/pep-0476/
[3] https://www.python.org/dev/peps/pep-0493/

I got an error while executing django-admin startproject newDjango as invalide syntax

(newDjango) C:\Python34\Scripts\newDjango>C:\Python34\Scripts\newDjango\Scripts\django-admin.exe startproject newDjango .
Traceback (most recent call last):
File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "C:\Python34\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Python34\Scripts\newDjango\Scripts\django-admin.exe\__main__.py", line 5, in <module>
File "c:\python34\scripts\newdjango\lib\site-packages\django\core\management\__init__.py", line 11, in <module>
from django.conf import settings
File "c:\python34\scripts\newdjango\lib\site-packages\django\conf\__init__.py", line 18, in <module>
from django.utils.functional import LazyObject, empty
File "c:\python34\scripts\newdjango\lib\site-packages\django\utils\functional.py", line 12
return _curried_func(*args, *moreargs, **{**kwargs, **morekwargs})
^
SyntaxError: invalid syntax
If you are using python 3.4, then make sure you have Django 2.0 installed.
With python 3.4, Django 2.1x throws the above error.
Run the command to install django:
pip3 install Django==2.0.0
Verify the version:
$ python -m django --version
2.0
$ python -V
Python 3.4.0
This should resolve your issue.

CKAN server down after installing ckanext-plugin extension

I'm trying to install the CKAN ckanext-spatial plugin by following the step-by-step instructions listed below.
http://docs.ckan.org/projects/ckanext-spatial/en/latest/install.html#ubuntu-12-04-postgresql-9-1-and-postgis-1-5
After installation and configuration, I get the following apache server error when trying to access the site homepage. CKAN is currently unusable. Do I need to upgrade the version of GeoAlchemy or is this an issue with the extension?
mod_wsgi (pid=29881): Target WSGI script '/etc/ckan/default/apache.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=29881): Exception occurred processing WSGI script '/etc/ckan/default/apache.wsgi'.
Traceback (most recent call last):
File "/etc/ckan/default/apache.wsgi", line 10, in
application = loadapp('config:%s' % config_filepath)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, **kw)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 271, in loadobj
global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 296, in loadcontext
global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 320, in _loadconfig
return loader.get_context(object_type, name, global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 454, in get_context
section)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 476, in _context_from_use
object_type, name=use, global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 406, in get_context
global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 296, in loadcontext
global_conf=global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 328, in _loadegg
return loader.get_context(object_type, name, global_conf)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 620, in get_context
object_type, name=name)
File "/usr/lib/ckan/default/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 646, in find_egg_entry_point
possible.append((entry.load(), protocol, entry.name))
File "/usr/lib/ckan/default/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg/pkg_resources.py", line 1989, in load
entry = import(self.module_name, globals(),globals(), ['name'])
File "/usr/lib/ckan/default/src/ckan/ckan/config/middleware.py", line 26, in
from ckan.config.environment import load_environment
File "/usr/lib/ckan/default/src/ckan/ckan/config/environment.py", line 17, in
import ckan.model as model
File "/usr/lib/ckan/default/src/ckan/ckan/model/init.py", line 7, in
import vdm.sqlalchemy
File "/usr/lib/ckan/default/lib/python2.7/site-packages/vdm/sqlalchemy/init.py", line 32, in
from tools import Repository
File "/usr/lib/ckan/default/lib/python2.7/site-packages/vdm/sqlalchemy/tools.py", line 33, in
raise ValueError("VDM only works with SQLAlchemy versions 0.4 through 0.7, not: %s" % sqav)
ValueError: VDM only works with SQLAlchemy versions 0.4 through 0.7, not: 1.0.12
To reiterate the important bit, the error message says:
VDM only works with SQLAlchemy versions 0.4 through 0.7, not: 1.0.12
So it looks like you upgraded SQLAlchemy to the latest version somehow. This happens if you use the --upgrade flag when pip installing something, although the instructions you mention don't say to do that, so I'm not quite sure how you ended up with this version of SQLAlchemy.
I suggest you install the vdm and SQLAlchemy combination that is in the current ckan requirements which is currently:
pip install SQLAlchemy==0.9.6 vdm==0.13
and I believe this is backwards compatible with all ckan versions. (Remember to run pip with your virtualenv activated)
Fixed it using the following command to correct my version of sqlalchemy.
pip install -r /usr/lib/ckan/default/src/ckan/pip-requirements.txt.
This seemed to fix the error.

Flask Login: TypeError: decoding Unicode is not supported

I am running flask, pymongo and flask-login as a stack.
My flask app is running fine locally, but once I deploy it with uwsgi on nginx, I get a strange unicode error from flask_login extension.
In short:
TypeError: decoding Unicode is not supported
Traceback:
[pid: 21753|app: 0|req: 5/5] 84.207.253.34 () {38 vars in 600 bytes} [Thu Jun 13 16:51:08 2013] GET / => generated 0 bytes in 4 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
Traceback (most recent call last):
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1473, in full_dispatch_request
rv = self.preprocess_request()
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask/app.py", line 1666, in preprocess_request
rv = func()
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask_login.py", line 311, in _load_user
deleted = self._session_protection()
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask_login.py", line 325, in _session_protection
ident = _create_identifier()
File "/myproject/myproject-env/local/lib/python2.7/site-packages/flask_login.py", line 133, in _create_identifier
request.headers.get("User-Agent")), 'utf8', errors='replace')
TypeError: decoding Unicode is not supported
Why is this not happening in dev environment? Hence it must be somehow related to uwsgi on nginx. Any suggestions? Many Thanks
The problem won't be solved by downgrading flask alone, because even installing flask==0.9 would install the latest dependencies, which is the bad werkzeug==0.9
Hence you better install the following in this order:
pip install werkzeug==0.8.3
pip install flask==0.9
pip install Flask-Login==0.1.3
flask login, can then be the latest version 0.1.3. No harm done there.
This stack works for me.
Hope this helps, until the emergency patch is out.
I am having the very same problem on my dev environment, with Flask 0.10 and Flask-Login 0.1.3
looks like flask 0.10 now has unicode request headers so flask-login explodes when trying to encode an already encoded string...
Flask_login people are already working on it:
https://github.com/maxcountryman/flask-login/issues/78
(EDIT) instant road to temporary happiness (as seen in github twin thread, thx Kofalt & Kave!)
pip uninstall flask ; pip uninstall werkzeug ; pip uninstall Flask-Login ; pip install werkzeug==0.8.3 ; pip install flask==0.9 ; pip install Flask-Login==0.1.3
My fork which fixes this issue:
https://github.com/jgelens/flask-login/tree/0.1.4
Install using:
pip install https://github.com/jgelens/flask-login/archive/0f07b8fa783c40d09cb284d442a526f067bab28b.zip#egg=flask-login
As per losu S., this looks to be a Flask 0.10 problem. Try to install previous version of Flask in your virtual environment using:
pip install Flask==0.9