Getting unnicode error when print in html Flask.
Here is my code.
{% if(backpaths) %}
{% for n in backpaths:%}
{% print '%s'%n %}
</br>
{% endfor %}
{% endif %}
I tried to use n.decode('utf-8') but it didn't work and got same error
backpaths is set to:
['1\xe6\x9c\x89 --(HYPER)--> quantifier={indefinite|\xe4\xb8\x8d\xe5\xae\x9a\xe6\x8c\x87} --(HYPO)--> \xe6\x9c\x89 ', '2\xe6\x9c\x89 --(HYPER)--> exist|\xe5\xad\x98\xe5\x9c\xa8 --(HYPO)--> \xe6\x9c\x89 ']
here is the traceback
(most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ganchimeg/FlaskApp/FlaskApp/__init__.py", line 125, in homepage
return render_template('index.html', backpaths=successPaths)
File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 128, in render_template
context, ctx.app)
File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 110, in _render
rv = template.render(context)
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/ganchimeg/FlaskApp/FlaskApp/templates/index.html", line 31, in top-level template code
{{ n }}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 16: ordinal not in range(128)
You don't have Unicode strings, you have byte strings. Python tries to implicitly decode those using the standard ASCII codec. Explicitly decode them:
{% if(backpaths) %}
{% for n in backpaths:%}
{{ n.decode('utf8') }}
</br>
{% endfor %}
{% endif %}
It'll be better if you passed in backpaths into the template ready-decoded.
Related
airflow cfg settings related to celery are:
broker_url = 'amqp://guest:guest#rabbitmq_server:8080'
celery_result_backend = db+postgresql://developer:password#postgres_server:5432/db_name
The airflow webserver runs ok, but while running a task from airflow UI I get the error.
I am error while running airflow scheduler,tracecak is:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python2.7/dist-packages/flask_admin/base.py", line 69, in inner
return self._run_view(f, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask_admin/base.py", line 368, in _run_view
return fn(self, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/flask_login.py", line 755, in decorated_view
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/airflow/www/utils.py", line 125, in wrapper
return f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/airflow/www/utils.py", line 172, in wrapper
return f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/airflow/www/views.py", line 952, in run
executor.heartbeat()
File "/usr/local/lib/python2.7/dist-packages/airflow/executors/base_executor.py", line 124, in heartbeat
self.execute_async(key, command=command, queue=queue)
File "/usr/local/lib/python2.7/dist-packages/airflow/executors/celery_executor.py", line 80, in execute_async
args=[command], queue=queue)
File "/usr/local/lib/python2.7/dist-packages/celery/app/task.py", line 536, in apply_async
**options
File "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 734, in send_task
with self.producer_or_acquire(producer) as P:
File "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 863, in producer_or_acquire
producer, self.producer_pool.acquire, block=True,
File "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 1233, in producer_pool
return self.amqp.producer_pool
File "/usr/local/lib/python2.7/dist-packages/celery/app/amqp.py", line 614, in producer_pool
self.app.connection_for_write()]
File "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 760, in connection_for_write
return self._connection(url or self.conf.broker_write_url, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/celery/app/base.py", line 828, in _connection
'broker_connection_timeout', connect_timeout
File "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 179, in __init__
if not get_transport_cls(transport).can_parse_url:
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/__init__.py", line 83, in get_transport_cls
_transport_cache[transport] = resolve_transport(transport)
File "/usr/local/lib/python2.7/dist-packages/kombu/transport/__init__.py", line 64, in resolve_transport
raise KeyError('No such transport: {0}'.format(transport))
KeyError: u'No such transport: '
My module versions are:
airflow==1.8
celery==4.1.0
kombu==4.1.0
python==2.7.12
I wasted lot of time on this issue, the reason for this error was quotation marks in broker_url = 'amqp://guest:guest#rabbitmq_server:8080' just removing the quotes: broker_url = amqp://guest:guest#rabbitmq_server:8080 solved the problem.
I am following this basic tutorial from the link exactly:
https://www.tutorialspoint.com/flask/flask_mail.htm
Anyone know what cause this problem? I think it should be a common problem?
Is there any additional setting for flask mail?
Here is the full error msg:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/boxia/PycharmProjects/learn_flask/test.py", line 18, in index
mail.send(msg)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask_mail.py", line 491, in send
with self.connect() as connection:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask_mail.py", line 144, in __enter__
self.host = self.configure_host()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/flask_mail.py", line 156, in configure_host
host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 1029, in __init__
source_address)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 1037, in _get_socket
server_hostname=self._host)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 401, in wrap_socket
_context=self, _session=session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 808, in __init__
self.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 1061, in do_handshake
self._sslobj.do_handshake()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ssl.py", line 683, in do_handshake
self._sslobj.do_handshake()
the python version is 2.8.2 and using it in eclipse. I am getting this error when I am trying to execute the following command:
The function is:
#api.one
#api.depends('image')
def _compute_image_details(self):
if self.image:
image_content = self.image.decode('base64')
print type(self.image)
print type(image_content)
# File size
self.size = len(image_content)
# Camera make and model from EXIF tags
img = PIL.Image.open(image_content)
exif_tags = img._getexif()
# 0x010f is a numeric code for the "make" exif field
# You can find a list of fields here: exiv2.org/tags.html
self.camera_maker = exif_tags.get(0x010f)
The error which is raised is:
Traceback (most recent call last):
File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 537, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 574, in dispatch
result = self._call_function(**self.params)
File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 310, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/next/WORKSPACE/odoo-8.0/openerp/service/model.py", line 113, in wrapper
return f(dbname, *args, **kwargs)
File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 307, in checked_call
return self.endpoint(*a, **kw)
File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 803, in __call__
return self.method(*args, **kw)
File "/home/next/WORKSPACE/odoo-8.0/openerp/http.py", line 403, in response_wrap
response = f(*args, **kw)
File "/home/next/WORKSPACE/odoo-8.0/addons/web/controllers/main.py", line 944, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/next/WORKSPACE/odoo-8.0/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/home/next/WORKSPACE/odoo-8.0/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/next/WORKSPACE/odoo-8.0/openerp/api.py", line 363, in old_api
result = method(recs, *args, **kwargs)
File "/home/next/WORKSPACE/odoo-8.0/openerp/models.py", line 5873, in onchange
newval = record[name]
File "/home/next/WORKSPACE/odoo-8.0/openerp/models.py", line 5571, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/home/next/WORKSPACE/odoo-8.0/openerp/fields.py", line 820, in __get__
self.determine_draft_value(record)
File "/home/next/WORKSPACE/odoo-8.0/openerp/fields.py", line 928, in determine_draft_value
self._compute_value(record)
File "/home/next/WORKSPACE/odoo-8.0/openerp/fields.py", line 867, in _compute_value
self.compute(records)
File "/home/next/WORKSPACE/odoo-8.0/openerp/api.py", line 239, in wrapper
return new_api(self, *args, **kwargs)
File "/home/next/WORKSPACE/odoo-8.0/openerp/api.py", line 397, in new_api
result = [method(rec, *args, **kwargs) for rec in self]
File "/home/next/WORKSPACE/odoo-8.0/addons/transform_webservice_example/image_example.py", line 33, in _compute_image_details
img = PIL.Image.open(image_content)
File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1955, in open
fp = __builtin__.open(fp, "rb")
TypeError: file() argument 1 must be encoded string without NULL bytes, not str
Please help me with this issue.
The other references say about the URL of the file. This is different scenario.
You're trying to open the base64 decoded contents of the file, you're supposed to open the file itself.
PIL.Image.open(self.image)
take this for example, to reproduce the error you're getting
>>> open('\0')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: file() argument 1 must be encoded string without NULL bytes, not str
>>>
the character '\0' is seen as a NullByte which the decoded image contains
I recently upgraded to pymongo 3.0 and was getting the same error mentioned here. The accepted answer fixed the read preferences error and my application is running. However whenever I try to run a query I am now getting a new error and was wondering if anyone else had run into this.
Here is the Traceback.
Traceback (most recent call last):
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask_login.py", line 756, in decorated_view
elif not current_user.is_authenticated():
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/werkzeug/local.py", line 338, in __getattr__
return getattr(self._get_current_object(), name)
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/werkzeug/local.py", line 297, in _get_current_object
return self.__local()
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask_login.py", line 46, in <lambda>
current_user = LocalProxy(lambda: _get_user())
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask_login.py", line 794, in _get_user
current_app.login_manager._load_user()
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask_login.py", line 363, in _load_user
return self.reload_user()
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/flask_login.py", line 325, in reload_user
user = self.user_callback(user_id)
File "/mongo_login/mongo_login/app/auth/views.py", line 79, in load_user
user.get_by_id(id)
File "/mongo_login/mongo_login/app/auth/users.py", line 23, in get_by_id
dbUser = models.User.objects.with_id(id)
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/mongoengine/queryset/base.py", line 600, in with_id
return queryset.filter(pk=object_id).first()
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/mongoengine/queryset/base.py", line 309, in first
result = queryset[0]
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/mongoengine/queryset/base.py", line 160, in __getitem__
return queryset._document._from_son(queryset._cursor[key],
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/mongoengine/queryset/base.py", line 1410, in _cursor
**self._cursor_args)
File "/mongo_login/mongo_login_env/lib/python2.6/site-packages/pymongo/collection.py", line 929, in find
return Cursor(self, *args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'snapshot'
There is an open bug on MongoEngine's GitHub.
The workaround appears to be using Pymongo 2.7.2.
I have two ipynb files in two folders. Once converts no problem, the other wont convert. Am I doing something wrong? I am converting to html
File 1:
cd C:\Users\rcreedon\Dropbox\GIZSupervisor\DATA\Production_Data\STP_Data\Data_Sets\Wave1\1004
ipython nbconvert 1004ProdData.ipynb --to html
A total success
File 2:
cd C:\Users\rcreedon\Dropbox\GIZSupervisor\DATA\Production_Data\STP_Data\Data_Sets\Wave1\1006
ipython nbconvert 1006prodData.ipynb --to html
A Horrid failure.
Error message looks like this
C:\Users\rcreedon\Dropbox\GIZSupervisor\DATA\Production_Data\STP_Data\Data_Sets
Wave1\1006>ipython nbconvert 1006ProdData.ipynb --to html
[NbConvertApp] Using existing profile dir: u'C:\Users\rcreedon\.ipython\pro
ile_default'
[NbConvertApp] Converting notebook 1006ProdData.ipynb to html
[NbConvertApp] Support files will be in 1006ProdData_files\
[NbConvertApp] Loaded template html_full.tpl
[NbConvertApp] ERROR | Error while converting '1006ProdData.ipynb'
Traceback (most recent call last):
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\nbconvertapp.py", line
00, in convert_notebooks
output, resources = exporter.from_filename(notebook_filename, resources=res
urces)
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters\exporter.py",
line 289, in from_filename
return self.from_notebook_node(nbformat.read(f, 'json'), resources=resource
,**kw)
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters\exporter.py",
line 260, in from_notebook_node
output = self.template.render(nb=nb_copy, resources=resources)
File "C:\Anaconda\lib\site-packages\jinja2\environment.py", line 969, in rend
r
return self.environment.handle_exception(exc_info, True)
File "C:\Anaconda\lib\site-packages\jinja2\environment.py", line 742, in hand
e_exception
reraise(exc_type, exc_value, tb)
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
tml_full.tpl", line 1, in top-level template code
{%- extends 'html_basic.tpl' -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
tml_basic.tpl", line 1, in top-level template code
{%- extends 'display_priority.tpl' -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
keleton\display_priority.tpl", line 1, in top-level template code
{%- extends 'null.tpl' -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
keleton\null.tpl", line 26, in top-level template code
{%- block body -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
tml_full.tpl", line 62, in block "body"
{{ super() }}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
keleton\null.tpl", line 29, in block "body"
{%- block any_cell scoped -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
keleton\null.tpl", line 76, in block "any_cell"
{%- block headingcell scoped-%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
tml_basic.tpl", line 64, in block "headingcell"
{{ ("#" * cell.level + cell.source) | replace('\n', ' ') | strip_math_space
| markdown2html | strip_files_prefix | add_anchor }}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\filters\markdown.py", l
ne 55, in markdown2html
return pandoc(source, 'markdown', 'html', extra_args=['--mathjax'])
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\utils\pandoc.py", line
4, in pandoc
"http://johnmacfarlane.net/pandoc/installing.html"
PandocMissing: The command 'pandoc -f markdown -t html --mathjax' returned an e
ror: [Error 2] The system cannot find the file specified.
Please check that pandoc is installed:
http://johnmacfarlane.net/pandoc/installing.html
not sure if this is still active or not, but a very similar problem was solved for me by adding the cabal binary path (ex $HOME/.cabal/bin) to bash $PATH.