0

First I get this UnicodeError, which on my local machine runs as is should without any error.

File "/home/malak/www/dev/shopvoice/dashboard/views/payment_view.py", line 126, in paypal_notify
     send_login_email_body = SEND_LOGIN_EMAIL_BODY % (user.email, random_pass) 
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 86: ordinal not in range(128)

When I print out the type of the 3 variables I get

user.email: <type 'unicode'>
SEND_LOGIN_EMAIL_BODY: <type 'str'>
random_pass: <type 'str'>

First question: How is this possible in python3 ? When I rebuild this error on my local machine I get 3 variables of type string. Does something like "<type 'unicode'>" even exist in python 3?

Obviously, what first comes to mind, does it run in Python 2 on my server?

No!

Here comes the weird part of the Story:

This is the full Traceback of the error which obviously shows its python3.6:

[Tue Feb 07 20:39:50.764173 2017] [:error] [pid 21179:tid 140085013579520] Traceback (most recent call last):
[Tue Feb 07 20:39:50.764176 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 39, in inner
[Tue Feb 07 20:39:50.764189 2017] [:error] [pid 21179:tid 140085013579520]     response = get_response(request) subinterpreter.  Returning 0.
[Tue Feb 07 20:39:50.764192 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
[Tue Feb 07 20:39:50.764195 2017] [:error] [pid 21179:tid 140085013579520]     response = self._get_response(request)terpreter.  Returning 0.
[Tue Feb 07 20:39:50.764198 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
[Tue Feb 07 20:39:50.764201 2017] [:error] [pid 21179:tid 140085013579520]     response = self.process_exception_by_middleware(e, request)
[Tue Feb 07 20:39:50.764204 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
[Tue Feb 07 20:39:50.764207 2017] [:error] [pid 21179:tid 140085013579520]     response = wrapped_callback(request, *callback_args, **callback_kwargs)
[Tue Feb 07 20:39:50.764210 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/django/views/decorators/http.py", line 40, in inner
[Tue Feb 07 20:39:50.764213 2017] [:error] [pid 21179:tid 140085013579520]     return func(request, *args, **kwargs)
[Tue Feb 07 20:39:50.764216 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
[Tue Feb 07 20:39:50.764219 2017] [:error] [pid 21179:tid 140085013579520]     return view_func(*args, **kwargs)
[Tue Feb 07 20:39:50.764222 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/paypal/standard/ipn/views.py", line 99, in ipn
[Tue Feb 07 20:39:50.764224 2017] [:error] [pid 21179:tid 140085013579520]     ipn_obj.send_signals()
[Tue Feb 07 20:39:50.764227 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/paypal/standard/ipn/models.py", line 39, in send_signals
[Tue Feb 07 20:39:50.764230 2017] [:error] [pid 21179:tid 140085013579520]     valid_ipn_received.send(sender=self)
[Tue Feb 07 20:39:50.764233 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/django/dispatch/dispatcher.py", line 191, in send
[Tue Feb 07 20:39:50.764236 2017] [:error] [pid 21179:tid 140085013579520]     response = receiver(signal=self, sender=sender, **named)
[Tue Feb 07 20:39:50.764238 2017] [:error] [pid 21179:tid 140085013579520]   File "/home/malak/www/dev/shopvoice/dashboard/views/payment_view.py", line 126, in paypal_notify
[Tue Feb 07 20:39:50.764241 2017] [:error] [pid 21179:tid 140085013579520]     send_login_email_body = SEND_LOGIN_EMAIL_BODY % (user.email, random_pass)
[Tue Feb 07 20:39:50.764244 2017] [:error] [pid 21179:tid 140085013579520] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 86: ordinal not in range(128)

Look at

File "/home/malak/www/dev/shopvoice/venv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58,

Another thing is, apache says it uses python 2.7.6. Everytime I restart the Server I get this in my error.log

[Tue Feb 07 21:34:01.965700 2017] [mpm_event:notice] [pid 21175:tid 140085127694208] AH00489: Apache/2.4.7 (Ubuntu) mod_wsgi/3.4 Python/2.7.6 configured -- resuming normal operations

I am using Apache 2.4.7 on Ubuntu 14.04 running mod_wsgi for my Django 1.10 application with multiple Virtualhosts each with its own Virtualenv.

Second question: How do I configure mod_wsgi to use python3.6, which it obviously just does.

bratanKamil
  • 55
  • 1
  • 5
  • you need to build apache headers with the python you use for your project (probably a virtualenv) – Amin Etesamian Feb 07 '17 at 21:08
  • you can encode it with utf-8, some times ago I found same problem... maybe you can do with `user.email.encode('utf-8')` – binpy Feb 07 '17 at 21:09
  • @SancaKembang I know how to fix this error, the problem is that this error shouldn't need to be handled since its python 3, which uses unicode by default – bratanKamil Feb 07 '17 at 21:21
  • @Amin Etasamian how can I do this? Do you think this is the issue, and my code is running in python2 even though it says its python3.6? – bratanKamil Feb 07 '17 at 21:22
  • did you tried it with once apache and multiple python languages version? – binpy Feb 07 '17 at 21:30
  • I tried the code on my local machine with python3.6 and it works. However on my server its behaving like python 2 and throwing this error, which is weird because the Traceback says its using Python3.6 – bratanKamil Feb 07 '17 at 21:38
  • how many projects that is in your server now? – binpy Feb 07 '17 at 21:39
  • 1
    my previous projects that configured with multiple python version, once apache, inside once server. project `A` used python2.7, `B`, and other projects used python3.5... and I found this answer http://stackoverflow.com/a/32085001/6396981, "The mod_wsgi module for Apache is compiled for one Python version only. You cannot load more than one instance of mod_wsgi into Apache at the same time." finally I reconfigured all my projects to compatible with same python version... – binpy Feb 07 '17 at 22:55
  • 1
    The traceback doesn't indicate that you are running Python 3, but that the modules are inside a directory named `python3.6` (probably a `virtualenv` created by Python 3). It could be that `mod_wsgi` uses Python 2 but its Python path is set to that directory. Could you show your `mod_wsgi` configuration? – Antonis Christofides Feb 08 '17 at 08:11
  • Ok you are both right, it uses Python 2.7, I have to recompile the mod_wsgi to python3 and configure all my projects to python 3 – bratanKamil Feb 08 '17 at 12:08

1 Answers1

0

So much confusion around this. You need to uninstall libapache-mod-wsgi, and replace it with libapache-mod-wsgi-py3. Your apache is running py3, but mod_wsgi is not.

mlissner
  • 17,359
  • 18
  • 106
  • 169