Using non-ASCII app name via Apache server
I'm new to Django, so this is probably some kind of beginner's mistake. Django is set up to run via Apache and WSGI. It uses Python 3. The first app I wrote works fine. When I got to the second I wanted to use an app name that contained non-ASCII letters. But I can't get that to work at all. Can anyone explain what I'm doing wrong? I've failed to find the solution using Google. To isolate the problem, I tried to make a test app following the instructions in https://docs.djangoproject.com/en/1.9/intro/tutorial01/ but using the app name "appåäö". But trying to access the page gives me an error message: ImportError at /appåäö/ No module named 'appåäö' On the other hand, if I copy the file tree for my project, remove the SECURE_SSL_REDIRECT=True directive from settings.py, and run using "manage.py runserver", *then* it works just fine. It is somehow related to the WSGI environment. But how can I make it work? To give a bit more details, this is what I have done: 1. Added url(r'^appåäö/', include('appåäö.urls')) to urlpatterns in dynsite/urls.py (dynsite is the name of the directory with settings.py and similar files). 2. Run "./manage.py startapp appåäö" to create an initial app tree. 3. Created a file appåäö/urls.py with the contents from django.conf.urls import url from . import views urlpatterns = [ url(r'^$', views.index, name='index'), ] 4. Edited appåäö/views.py to look like this from django.http import HttpResponse def index(request): return HttpResponse("Hej världen!") 5. Restarted httpd 6. Point my browser to appåäö in my I attach the complete traceback I get. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d6db7796-931b-46b9-bd8e-7c4b78d49db3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. #traceback Description: Binary data
Re: Using non-ASCII app name via Apache server
M Hashmi: > List down your "civ.apps.CivConfig" also restart Gunicorn, and reload Nginx. I'm not sure exactly what you mean by "list down". Do you want me to comment it out? In any case, to make an even more clean test case, I replaced my Django site with one I built from scratch. I.e. I started by doing python3-django-admin startproject dynsite dyn And then the same steps as in my original message. (I'm not running Gunicorn or Nginx, I'm using Apache following the instructions on https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/ So httpd was what I restarted.) I attach the complete file tree after these steps. I still get the same backtrace as before. I believe I've made the site visible from the outside, so you should see the same if you point a browser to http://www.uddeborg.se/dyn/app%C3%A5%C3%A4%C3%B6/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/22440.20419.305454.59808%40gargle.gargle.HOWL. For more options, visit https://groups.google.com/d/optout. dyn.tar.gz Description: Test site contents
Re: Using non-ASCII app name via Apache server
M Hashmi: > Reply me back I am waiting. Apologies if my assumption caused your time. No need to apologize! You are trying to help me. I'm grateful. In doing my simplified test case, I forgot to add the new app to INSTALLED_APP. Thanks for the pointer! But after fixing that, I get an "Internal Server Error" instead, and the log files contains the traceback below. Some of the time stamps are in local time (UTC+2) and some are in UTC. I guess that is just some idiosyncrasy of Apache httpd and mod_wsgi. The test server, "./manage.py runserver" still works fine. (I also attach the updated site tree. There is just a small change, but the entire site is so small so I thought it was ok.) [Mon Aug 08 12:49:59.214434 2016] [core:notice] [pid 12016] SELinux policy enabled; httpd running as context system_u:system_r:httpd_t:SystemLow [Mon Aug 08 12:49:59.215009 2016] [ssl:info] [pid 12016] AH01887: Init: Initializing (virtual) servers for SSL [Mon Aug 08 12:49:59.215550 2016] [ssl:info] [pid 12016] AH01876: mod_ssl/2.4.23 compiled against Server: Apache/2.4.23, Library: OpenSSL/1.0.2h [Mon Aug 08 12:49:59.216226 2016] [suexec:notice] [pid 12016] AH01232: suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Mon Aug 08 12:49:59.252466 2016] [auth_digest:notice] [pid 12016] AH01757: generating secret for digest authentication ... [Mon Aug 08 12:49:59.252819 2016] [socache_shmcb:info] [pid 12016] AH00830: Shared memory socache initialised [Mon Aug 08 12:49:59.252826 2016] [ssl:info] [pid 12016] AH01887: Init: Initializing (virtual) servers for SSL [Mon Aug 08 12:49:59.253247 2016] [ssl:info] [pid 12016] AH01876: mod_ssl/2.4.23 compiled against Server: Apache/2.4.23, Library: OpenSSL/1.0.2h [Mon Aug 08 12:49:59.253272 2016] [http2:info] [pid 12016] AH03090: mod_http2 (v1.5.11, feats=CHPRIO+SHA256, nghttp2 1.7.1), initializing... [Mon Aug 08 12:49:59.254005 2016] [lbmethod_heartbeat:notice] [pid 12016] AH02282: No slotmem from mod_heartmonitor [Mon Aug 08 12:49:59.279641 2016] [wsgi:info] [pid 12021] mod_wsgi (pid=12021): Initializing Python. [Mon Aug 08 12:49:59.281769 2016] [mpm_prefork:notice] [pid 12016] AH00163: Apache/2.4.23 (Fedora) OpenSSL/1.0.2h-fips PHP/5.6.23 mod_wsgi/4.4.8 Python/3.5.1 configured -- resuming normal operations [Mon Aug 08 12:49:59.281802 2016] [mpm_prefork:info] [pid 12016] AH00164: Server built: Jul 18 2016 15:38:14 [Mon Aug 08 12:49:59.281815 2016] [core:notice] [pid 12016] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND' [Mon Aug 08 12:49:59.282035 2016] [wsgi:info] [pid 12020] mod_wsgi (pid=12020): Initializing Python. [Mon Aug 08 12:49:59.284088 2016] [wsgi:info] [pid 12027] mod_wsgi (pid=12027): Initializing Python. [Mon Aug 08 12:49:59.291791 2016] [wsgi:info] [pid 12022] mod_wsgi (pid=12022): Initializing Python. [Mon Aug 08 12:49:59.312125 2016] [wsgi:info] [pid 12043] mod_wsgi (pid=12043): Initializing Python. [Mon Aug 08 12:49:59.317964 2016] [wsgi:info] [pid 12020] mod_wsgi (pid=12020): Attach interpreter ''. [Mon Aug 08 12:49:59.320378 2016] [wsgi:info] [pid 12027] mod_wsgi (pid=12027): Attach interpreter ''. [Mon Aug 08 12:49:59.321265 2016] [wsgi:info] [pid 12020] mod_wsgi (pid=12020): Adding '/var/www/dyn' to path. [Mon Aug 08 12:49:59.323805 2016] [wsgi:info] [pid 12027] mod_wsgi (pid=12027): Adding '/var/www/dyn' to path. [Mon Aug 08 12:49:59.327720 2016] [wsgi:info] [pid 12022] mod_wsgi (pid=12022): Attach interpreter ''. [Mon Aug 08 12:49:59.330202 2016] [wsgi:info] [pid 12022] mod_wsgi (pid=12022): Adding '/var/www/dyn' to path. [Mon Aug 08 12:49:59.331290 2016] [wsgi:info] [pid 12021] mod_wsgi (pid=12021): Attach interpreter ''. [Mon Aug 08 12:49:59.334499 2016] [wsgi:info] [pid 12021] mod_wsgi (pid=12021): Adding '/var/www/dyn' to path. [Mon Aug 08 12:49:59.344669 2016] [wsgi:info] [pid 12043] mod_wsgi (pid=12043): Attach interpreter ''. [Mon Aug 08 12:49:59.347136 2016] [wsgi:info] [pid 12043] mod_wsgi (pid=12043): Adding '/var/www/dyn' to path. [Mon Aug 08 12:50:09.731008 2016] [wsgi:info] [pid 12020] mod_wsgi (pid=12020): Create interpreter 'www.uddeborg.se|/dyn'. [Mon Aug 08 12:50:09.740547 2016] [wsgi:info] [pid 12020] mod_wsgi (pid=12020): Adding '/var/www/dyn' to path. [Mon Aug 08 12:50:09.741401 2016] [wsgi:info] [pid 12020] [client 62.65.125.225:47982] mod_wsgi (pid=12020, process='', application='www.uddeborg.se|/dyn'): Loading WSGI script '/var/www/dyn/dynsite/wsgi.py'. [Mon Aug 08 10:50:10.059568 2016] [wsgi:error] [pid 12020] [client 62.65.125.225:47982] mod_wsgi (pid=12020): Target WSGI script '/var/www/dyn/dynsite/wsgi.py' cannot be loaded as Python module. [Mon Aug 08 10:50:10.059639 2016] [wsgi:error] [pid 12020] [client 62.65.125.225:47982] mod_wsgi (pid=12020): Exception occurred processing WSGI script '/var/www/dyn/dynsite/wsgi.py'. [Mon Aug 08 10:50:10.060501 2016] [wsgi:error] [pid 12020] [client 62.65.125.225:47982] Traceback (most recent call last): [Mon Aug 08 10:50:10.060566 2016] [wsgi:err
Re: Using non-ASCII app name via Apache server
> Please makemigrations/migrate and restart server. It says its not getting > proper data from wsgi.py. As my models.py is empty, I thought I didn't need to do any migration. But I've done so now just in case. It doesn't seem to change anything. > wsgi.py is not able to stream data to httpd because it has internal issues. Yes, I understand it fails with a traceback. What I don't understand is why it fails. > Also to see if project is working fine please always use runserver so you can > see django related errors. I briefly mentioned that. It works fine with runserver. No error message, and the page is served fine. There is obviously something different in the WSGI case. But what, I wonder. Most recent traceback from the httpd log: [Mon Aug 08 13:27:36.777315 2016] [wsgi:info] [pid 14003] [client 62.65.125.225:51998] mod_wsgi (pid=14003, process='', application='www.uddeborg.se|/dyn'): Loading WSGI script '/var/www/dyn/dynsite/wsgi.py'. [Mon Aug 08 11:27:37.084022 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] mod_wsgi (pid=14003): Target WSGI script '/var/www/dyn/dynsite/wsgi.py' cannot be loaded as Python module. [Mon Aug 08 11:27:37.084100 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] mod_wsgi (pid=14003): Exception occurred processing WSGI script '/var/www/dyn/dynsite/wsgi.py'. [Mon Aug 08 11:27:37.084961 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] Traceback (most recent call last): [Mon Aug 08 11:27:37.085025 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "/var/www/dyn/dynsite/wsgi.py", line 16, in [Mon Aug 08 11:27:37.085030 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] application = get_wsgi_application() [Mon Aug 08 11:27:37.085041 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "/usr/lib/python3.5/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application [Mon Aug 08 11:27:37.085046 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] django.setup() [Mon Aug 08 11:27:37.085055 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "/usr/lib/python3.5/site-packages/django/__init__.py", line 18, in setup [Mon Aug 08 11:27:37.085060 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] apps.populate(settings.INSTALLED_APPS) [Mon Aug 08 11:27:37.085070 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "/usr/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate [Mon Aug 08 11:27:37.085075 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] app_config = AppConfig.create(entry) [Mon Aug 08 11:27:37.085084 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "/usr/lib/python3.5/site-packages/django/apps/config.py", line 116, in create [Mon Aug 08 11:27:37.085089 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] mod = import_module(mod_path) [Mon Aug 08 11:27:37.085098 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "/usr/lib64/python3.5/importlib/__init__.py", line 126, in import_module [Mon Aug 08 11:27:37.085103 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] return _bootstrap._gcd_import(name[level:], package, level) [Mon Aug 08 11:27:37.085112 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "", line 986, in _gcd_import [Mon Aug 08 11:27:37.085121 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "", line 969, in _find_and_load [Mon Aug 08 11:27:37.085131 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "", line 944, in _find_and_load_unlocked [Mon Aug 08 11:27:37.085140 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "", line 222, in _call_with_frames_removed [Mon Aug 08 11:27:37.085149 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "", line 986, in _gcd_import [Mon Aug 08 11:27:37.085158 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "", line 969, in _find_and_load [Mon Aug 08 11:27:37.085168 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] File "", line 956, in _find_and_load_unlocked [Mon Aug 08 11:27:37.085189 2016] [wsgi:error] [pid 14003] [client 62.65.125.225:51998] ImportError: No module named 'app\xc3\xa5\xc3\xa4\xc3\xb6' -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/22440.28123.900658.308986%40gargle.gargle.HOWL. For more options, visit https://groups.google.com/d/optout.
Re: Using non-ASCII app name via Apache server
M Hashmi: > Can you kindly post your installed apps again and root urls.py in project > directory. Sure, it's attached in this mail too. > You said you have nothing in your app models so is there nothing at all in > app? Correct. To isolate the problem I've made a minimal app that doesn't do anything, just returns a message. Of course, the real app I'm writing contains some real logic. But this is a test case to try to understand where it goes wrong. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/22440.32799.23615.881465%40gargle.gargle.HOWL. For more options, visit https://groups.google.com/d/optout. dyn.tar.gz Description: Binary data
Re: Using non-ASCII app name via Apache server
M Hashmi: > http://stackoverflow.com/questions/728891/correct-way-to-define-python-source-code-encoding I'm using UTF-8 in Python 3 where it is the default. So that is probably not the issue. http://stackoverflow.com/questions/14083111/should-i-use-encoding-declaration-in-python3 -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/22440.32902.459446.548379%40gargle.gargle.HOWL. For more options, visit https://groups.google.com/d/optout.
Re: Using non-ASCII app name via Apache server
M Hashmi: > I am sorry but I need some time for R&D coz few things about encoding/decoding > are confusing. Agreed! :-) I've always found Python's encoding handling confusing. Not quite as much in Python 3 as in Python 2, but still. To rule out all eventualities, I made a second app called "ascii". It is identical to "appåäö" except for the name. In the trees, only the class name and its "name" attributein apps.py differ. If I comment out appåäö from INSTALLED_APPS in dynsite/settings.py and from urlpatterns in dynsite/urls.py, then it works just fine. If I include the appåäö again I get the internal server error and the backtrace in the log as before. That is also if it is the ascii app I try to access. I attach the updated site. > Can you also > try apt-get update/upgrade to get build releases. I upgraded, and I did get a newer django package. But it didn't make any difference. (And in case it matters, I'm using Fedora, not a Debian derivative. I guess I should have mentioned that.) -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/22440.35114.793613.275251%40gargle.gargle.HOWL. For more options, visit https://groups.google.com/d/optout. dyn.tar.gz Description: Updated test site
Re: Using non-ASCII app name via Apache server
For the benefit of anyone following this thread. I've found some relevant information, even if I don't understand the entire picture. The important point seems to be the locale in which the Apache server is running. The default Fedora configuration sets LANG=C for the httpd server. Apparently, that affects a lot of how Python behaves. By adding some configuration to set LANG to a UTF-8 locale, sv_SE.utf8 in my case, things started to work. I can now access both ascii and appåäö, and everything seems fine. Remains to be seen if I have changed some other behaviour of my server in some way. Even if I don't fully understand the interactions between the locale setting and the Python interpreter, it works for me now. I can continue my work on my original app. Thanks for the help! -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/22440.47636.729258.491836%40gargle.gargle.HOWL. For more options, visit https://groups.google.com/d/optout.