UnicodeEncodeError with django: inconsistent behavior - python

I deployed a project on webfaction with djanog. All went fine until recently, when all of a sudden I started to get this error: UnicodeEncodeError: 'ascii' codec can't encode characters in position 64-68: ordinal not in range(128)
The url is with Russian characters. But the matter is, when I restart Apache, there is no error any more. So it is kind of difficult for me to pin the error.

Read:
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/#if-you-get-a-unicodeencodeerror
Most likely you need to ensure that UTF-8 is set as the lang locale for the environment Apache runs under.
Otherwise you need to ensure you handle Unicode issues in your code yourself where appropriate.

This error comes because of filename or file contents cotains garbage collection or in another language (except english)..
So you can add unicode() for this. or check NLTK library of handling this situation.

I guess it has to do with webfaction or my incorrect dealing with Apache: actually, I had a restart Apache command in my crontab.
Found a similar question (dealing with Apache deliberately restarting), the webfaction guy suggested:
touch /path to /wsgi.py
instead of:
apache2/restart
after I replaced .../restart with the above line I have no more error messages.

Related

IEPY Package - Installation Error - Syntax Error - Python

I have some troubles in interpreting the documentation (http://iepy.readthedocs.io/en/latest/tutorial.html) commands of the Python IEPY package for Natural Language Processing. The first step to work with IEPY is to create an "instance" (as a non-programmer I have little idea what is it all about). They also provide the command to do it:
iepy --create <project_name>
My problem is that when I type the exact sentence into my command line, I get a "syntax error". I suppose that I do not follow some coding conventions and misinterpret what I should really type. Would be glad to hear what I do wrong.
Another source of the problem could be an improper installation of some of the additional libraries required for IEPY. After trying to install IEPY using
pip install iepy, I got a big fat error message after "collecting django-angular-0.7.8". The command line reports an "Exception", gives a reference to the line, where it happens and describes the source of an error (this is how I interpret the output at least). Which is:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xad in position
4: invalid start byte
Here is the screenshot (cannot use copy-paste in my command line)
Installation of IEPY: The Error Message While Installing IEPY
P.S. It looks that the documentation in general is Linux-users oriented while I am using Windows 8.1. Is it the source of my troubles?

In trying to install flask and virtualenv in PYTHON, there are two errors. 1. UnicodeDecodeError:'ascii' codec. (with REDIRECTION ISSUE) 2. OSError

As I described on the headline, I'm trying to install flask in python. After finishing installing virtualenv, in creating a virtual environment, when I enter 'virturalenv venv', I got two errors !
1. UnicodeDecodeError
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc7 in position 5: ordinal not in range(128)
I searched during a lot of time to find the solution, and I got a bunch of various solutions from other questions. And most of them is about encoding types such as 'cpc949', 'mbcs' and so on.
So I tried to replace 'ascii' to them(cpc949, mbcs or...), and I got a terrible error. The encoding type was redirected! Although I modified the encoding type in 'site.py' file, when I committed 'virtualenv venv' again at cmd in windows, the error shows again. After that, I checked site.py file again, the encoding type was redirected. It's odd.....
Any suggestions, comments or idea :) ?
2. OSError
OSError: Command C:\myproject\venv\Scripts\python.exe -c "import sys, pip; sys...d\"] + sys.argv[1:]))" setuptools pip failed with error code 2
with this, I have no idea at all. Who anybody has idea ??
.
And here is the photos of the errors :
https://drive.google.com/open?id=0BzJpcZZu99ZnMl9nQTFnS3VaSWM&authuser=0
https://drive.google.com/open?id=0BzJpcZZu99ZnOVh5RUtnSklTbDA&authuser=0
(because of my less reputation score)
Please help sir. Very thanks. Sincerely

Can't login to Enthought/Canopy

I have Enthought/Canopy installed on my Windows7X64.
It works fine until I try to login to Enthought server through Package Manager in order to install some additional packages. Then the next error occurs:
"WSGI Proxy "Server" Error.
'ascii' codec can't decode byte 0xe0 in position 0: ordinal not in range(128)"
I have no proxy, just direct internet connection.
Is there any workaround for this bug?
Quickest workaround is to switch OS's russian locale to english one.

Django: uploaded file encoding issues

On the development platform upload works just fine, but when I deploy and test on the server upload fails with the following error
UnicodeEncodeError at /upload
'ascii' codec can't encode characters in position 25-30: ordinal not in range(128)
I use
django-ajax-uploader,
Django version: 1.3.1,
Python version: 2.6
I believe it happens about files with Roman, Russian, Chinese filenames.
Also found similar discussion at
Why do I get a ASCII encoding error with Unicode data in Python 2.4 but not in 2.7?
but about differences about Python versions.
I tried to set environment $LANG variable to en_US.utf8 etc. but it didn't work.
Can anyone give me an advice or point a right way?
Thanks,
Sultan
See If you get a UnicodeEncodeError in the django docs.
Personally, I prefer to rename uploaded files to ASCII charset to avoid other problems as well. Here is a link to an article with code that describes subclassing FileSystemStorage .

Python Unittest fails to start on some syntax error without mentioning source of error

I am working on an web application using flask, postgresql and sqlalchemy and coding in Eclipse.
I am using python unittest to test basic functions.
So I was editing my code and by mistake I typed ∫ in a comment. Since it was in a comment I did not bother to remove it(I know about encodings and all but still I did it!) I ran my unittest and it did not run any test for obvious reason. But the problem is I was not able to find reason of error until I ran the local server and then I was able to find the error.
I have similar problems in past where some unknown small mistake stops my test to even begin without even informing me the source of error.
So my question is there any way to find source of error while using python unittest module and avoid situations like mentioned above?
Running a basic unittest example with a # ∫ comment added gives me the following error:
File "example.py", line 4
SyntaxError: Non-ASCII character '\xe2' in file x.py on line 4, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
With python -m unittest example I get the same exception (with a somewhat longer backtrace).
So it seems this is not an unittest issue.
Are you using an Eclipse plugin to run your tests? If so, try running it from the command line; if that works fine this is likely a bug in that plugin.

Categories

Resources