2

I'm at a loss even as to where the problem lies, so I'll give you the full background.

I set up a django app on my Linux server, with nginx and gunicorn, and started with a toy example.

Here's urls.py:

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^(.*)/', views.helloworld),
    url(r'^$', views.homepage),
]

And here's views.py:

from django.shortcuts import render
from django.http import HttpResponse

def helloworld(request, string):
    return HttpResponse("Hello World! " + string)

def homepage(request):
    return HttpResponse("Homepage!")

For the app I'm working on it's imperative that I be able to handle non-ascii characters in the url, so I tested by visiting . With ./manage.py runserver, everything works as intended: I'm redirected to /é/ (with a trailing slash), and "Hello World! é" is printed back.

When I deploy it on the server, though, the behavior changes. If I visit /é/, with the trailing slash, I get "Hello World! %C3%A9", without the percent encoding being decoded. Fine, I don't know why the behavior is different, but I can live with that.

If I visit though, without the trailing slash, then as the trailing slash is added, I get redirected to /%25C3%25A9/, with the percent signs themselves double encoded. I would like to avoid the %25, but I don't know who's adding them, or how to disable it.

Help please?


If helpful, here's the nginx config (relevant part):

upstream app_server_2 {
    server 127.0.0.1:7000 fail_timeout=0;
}

server {
    listen 80;
    listen [::]:80;

    root /usr/share/nginx/html;
    index index.html index.htm;

    [...]

    location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server_2;
    }
}
  • Could these be related? [Disabling URL decoding in nginx proxy](http://serverfault.com/questions/459369/disabling-url-decoding-in-nginx-proxy) and [External links URL encoding leads to '%3F' and '%3D' on Nginx server](http://stackoverflow.com/questions/20470191/external-links-url-encoding-leads-to-3f-and-3d-on-nginx-server) – Lukas Graf Dec 10 '15 at 22:57
  • These links don't seem to help; also, I experience the same problem even if I manually run gunicorn (bypassing nginx), so I guess we can rule out nginx as the cause. – Riff Schelder Dec 11 '15 at 04:17
  • Did you manage to resolve it? I have the same problem... :/ – palamunder Jul 09 '17 at 20:06
  • It was something like an async module that was causing the problem. I disabled it and the problem went away. I didn't investigate. (Also, since this is almost two years ago, I'm not sure I'm remembering it right.) – Riff Schelder Jul 10 '17 at 20:41

0 Answers0