2011-12-30 2 views
1

나는 this thread을 따르고 있으며 peppergrower가 채택한 코드입니다. 내가 URL로 암호화 인용 문자를 추가하고 접근이 URL을 시도 할 때, 장고는 다음과 같은 오류와 함께 실패장고는 URL에 인용 된 문자를 사용할 수 없습니까?

Traceback (most recent call last):

File "C:\Python27\lib\site-packages\django\core\servers\basehttp.py", line 283, in run self.result = application(self.environ, self.start_response)

File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 68, in call return self.application(environ, start_response)

File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 264, in call logger.warning('Bad Request (UnicodeDecodeError): %s' % request.path,

UnboundLocalError: local variable 'request' referenced before assignment

같은 종류의 샘플 URL이 http://localhost:8000/customer/unsubscribe/%F1%CDE%A2%9DL%BF%21W%60%FF%04%D2%D2%3B%B1%FB%C9%8Ff%89%06O%FFY%E2_%16%9BnPM/입니다. URL에 %가 표시되는 한 장고는 예외를 초과 할 것입니다. 따옴표 붙은 문자는 이미 유니 코드가 0이므로 이해가되지 않습니다. 내가

+0

... 우리는 당신이 같은 서비스가 우리의 시스템에서 실행하지 않아도됩니다. 대신 코드를 제공 할 수 있습니까? – Makoto

+0

실제로 장고의 오류 처리 버그가있는 것 같습니다. 그것과 같은 핵심 Django 코드에는'UnboundLocalError'가 있어서는 안됩니다. – dkamins

+0

예, dkamins, 참으로 버그입니다. 진짜 오류는 django가 따옴표로 묶인 유니 코드의 일부이므로 URL에서 %를 처리 할 수 ​​없습니다. 그러나 오류가 발생하면 UnboundLocalError가 발생합니다. 어쨌든 django doc이 말한 것처럼 따옴표로 묶인 unicode가 제대로 작동해야한다는 것은 실망 스럽지만 실제로는 그렇지 않습니다. –

답변

0

이 문제 https://code.djangoproject.com/ticket/16541https://code.djangoproject.com/ticket/5738 관련된 몇 장고 티켓이 있습니다 장고 1.3.1을 사용하고

. 아래 부분에 주어진 # 5738에 Malcolm's comment 특히 : A는 URI가 우리에게 어떠한 영향도주지 않습니다 로컬 호스트

The problem is that although UTF-8 is strongly recommended as the encoding for non-ASCII data, it's not actually codified in any spec until quite recently (RFC 2396 leaves things wide open, for example). Only in RFC 3986 were things made clear for IRI to URI encoding.

In the interim, systems were deployed that spit out non-UTF-8 encoded URIs.

So I'm going to commit a change that passes back a 400 response for malformed input (non-UTF-8) but also makes it easier to override the request class, so if somebody is dealing with a legacy system, they can subclass WSGIRequestor or ModPythonRequest to handle decoding the URI however they need to.

+0

필자의 경우 유니 코드는 URL에서 안전해야하는 ASCII 텍스트가되기 위해 "인용"되어있다. 나는 이런 종류의 "인용 된"URL로 많은 웹 사이트를 보았습니다. Django는 url을 캡쳐하고 자동으로 "unquote"하지만 (나에게 보이는 것처럼 보이지만) 제대로 처리하지 못합니다. –

+0

주석을 정확하게 읽는다면 UTF-8이 아닌 경우 처리 할 수 ​​없다는 의미입니다. –

+0

그럴듯한 것 같습니다. 내가 URL에 직접 unicode (따옴표 붙은 것이 아닌)가 있다면, 장고는 괜찮다고 생각하는 것 같습니다. –

관련 문제