简体   繁体   中英

mod_wsgi says python 2.7 is configured, code running in python 3.6

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM