[GH-ISSUE #214] Ошибка #162

Closed
opened 2026-10-13 19:50:17 +00:00 by bsakaguchi · 10 comments
Owner

Originally created by @skaa on GitHub (Apr 19, 2017).
Original GitHub issue: https://github.com/werwolfby/monitorrent/issues/214

Originally assigned to: @werwolfby on GitHub.

При открытии http://localhost:6687/ в консоли ошибки:

UnicodeEncodeError('latin-1', 'Натали-ПК', 0, 6, 'ordinal not in range(256)')
Traceback (most recent call last):
  File "C:\Program Files (x86)\Monitorrent\env\lib\site-packages\cheroot\server.py", line 966, in communicate
    req.respond()
  File "C:\Program Files (x86)\Monitorrent\env\lib\site-packages\cheroot\server.py", line 796, in respond
    self.send_headers()
  File "C:\Program Files (x86)\Monitorrent\env\lib\site-packages\cheroot\server.py", line 910, in send_headers
    self.server.server_name.encode('ISO-8859-1'),
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-5: ordinal not in range(256)

видимо дело в том, что компьютер с виндой имеет сетевое имя Натали-ПК. Кстати этот текст повторяется несколько раз, хотя запрос из браузера выполнялся только один.

Originally created by @skaa on GitHub (Apr 19, 2017). Original GitHub issue: https://github.com/werwolfby/monitorrent/issues/214 Originally assigned to: @werwolfby on GitHub. При открытии http://localhost:6687/ в консоли ошибки: ``` UnicodeEncodeError('latin-1', 'Натали-ПК', 0, 6, 'ordinal not in range(256)') Traceback (most recent call last): File "C:\Program Files (x86)\Monitorrent\env\lib\site-packages\cheroot\server.py", line 966, in communicate req.respond() File "C:\Program Files (x86)\Monitorrent\env\lib\site-packages\cheroot\server.py", line 796, in respond self.send_headers() File "C:\Program Files (x86)\Monitorrent\env\lib\site-packages\cheroot\server.py", line 910, in send_headers self.server.server_name.encode('ISO-8859-1'), UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-5: ordinal not in range(256) ``` видимо дело в том, что компьютер с виндой имеет сетевое имя Натали-ПК. Кстати этот текст повторяется несколько раз, хотя запрос из браузера выполнялся только один.
bsakaguchi 2026-10-13 19:50:17 +00:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@byg0n3 commented on GitHub (Apr 19, 2017):

Классика проблем с кодировкой и виндовая реализация cp1251. По факту - проблема в сторонней либе (и, кстати, так и не понятно, зачем они насильно пытаются это делать, если браузеры нынче могут в нормальный диапазон символов).

В качестве локального решения может помочь изменение hostname на что-нибудь в латинском исполнении (Natali-PC).

По коду - https://github.com/werwolfby/monitorrent/blob/develop/server.py#L188 и падает на https://github.com/cherrypy/cheroot/blob/master/cheroot/server.py#L884

<!-- gh-comment-id:295394064 --> @byg0n3 commented on GitHub (Apr 19, 2017): Классика проблем с кодировкой и виндовая реализация cp1251. По факту - проблема в [сторонней либе](https://github.com/cherrypy/cheroot) (и, кстати, так и не понятно, зачем они насильно пытаются это делать, если браузеры нынче могут в нормальный диапазон символов). В качестве локального решения может помочь изменение hostname на что-нибудь в латинском исполнении (Natali-PC). По коду - https://github.com/werwolfby/monitorrent/blob/develop/server.py#L188 и падает на https://github.com/cherrypy/cheroot/blob/master/cheroot/server.py#L884
Author
Owner

@werwolfby commented on GitHub (Apr 19, 2017):

Из rfc:

By default, message header field parameters in Hypertext Transfer
Protocol (HTTP) messages cannot carry characters outside the ISO-
8859-1 character set. RFC 2231 defines an encoding mechanism for use

Так что похоже что логично :(. Надо наверное будет захардкодать имя сервера.

<!-- gh-comment-id:295417997 --> @werwolfby commented on GitHub (Apr 19, 2017): Из [rfc](https://tools.ietf.org/html/rfc5987): > By default, message header field parameters in Hypertext Transfer > Protocol (HTTP) messages cannot carry characters outside the ISO- > 8859-1 character set. RFC 2231 defines an encoding mechanism for use Так что похоже что логично :(. Надо наверное будет захардкодать имя сервера.
Author
Owner

@byg0n3 commented on GitHub (Apr 19, 2017):

Это стандартная рекомендация для совместимости с RFC 2231.
Раздел 3.2 особенно подчеркивает, что это не является обязательным требованием:

However, RFC 2231 does not specify a mandatory-to-implement character
set, making it hard for senders to decide which character set to use.
Thus, recipients implementing this specification MUST support the
character sets "ISO-8859-1" [ISO-8859-1] and "UTF-8" [RFC3629].

В придачу, w3 также не настаивает на использовании "ISO-8859-1".

Я бы завел тикет в cheroot для начала и спросил о возможности использования дефолтного utf-8. За спрос не бьют, как говорится.

<!-- gh-comment-id:295449357 --> @byg0n3 commented on GitHub (Apr 19, 2017): Это стандартная рекомендация для совместимости с RFC 2231. Раздел [3.2](https://tools.ietf.org/html/rfc5987#section-3.2) особенно подчеркивает, что это не является обязательным требованием: > However, RFC 2231 does not specify a mandatory-to-implement character set, making it hard for senders to decide which character set to use. Thus, recipients implementing this specification MUST support the character sets "ISO-8859-1" [ISO-8859-1] and "UTF-8" [RFC3629]. В придачу, [w3](https://www.w3.org/International/articles/http-charset/index#charset) также не настаивает на использовании "ISO-8859-1". Я бы завел тикет в cheroot для начала и спросил о возможности использования дефолтного `utf-8`. За спрос не бьют, как говорится.
Author
Owner

@werwolfby commented on GitHub (Apr 19, 2017):

Согласен, спасибо

<!-- gh-comment-id:295471220 --> @werwolfby commented on GitHub (Apr 19, 2017): Согласен, спасибо
Author
Owner

@webknjaz commented on GitHub (May 5, 2017):

@werwolfby
I've raised this question @ https://github.com/cherrypy/cheroot/issues/27

<!-- gh-comment-id:299448627 --> @webknjaz commented on GitHub (May 5, 2017): @werwolfby I've raised this question @ https://github.com/cherrypy/cheroot/issues/27
Author
Owner

@werwolfby commented on GitHub (May 5, 2017):

@webknjaz thanks a lot!

<!-- gh-comment-id:299473228 --> @werwolfby commented on GitHub (May 5, 2017): @webknjaz thanks a lot!
Author
Owner

@webknjaz commented on GitHub (Jun 18, 2017):

@werwolfby while I'm not sure about the way we'd fix this in cheroot, I suggest you specifying the server name explicitly in this call as a workaround.

It would look smth like:

server = wsgi.Server(server_start_params, app, server_name='Monitorrent Server/v100500')
<!-- gh-comment-id:309296688 --> @webknjaz commented on GitHub (Jun 18, 2017): @werwolfby while I'm not sure about the way we'd fix this in cheroot, I suggest you specifying the server name explicitly in [this call](https://github.com/werwolfby/monitorrent/blob/6fb0ad3/server.py#L188) as a workaround. It would look smth like: ```python server = wsgi.Server(server_start_params, app, server_name='Monitorrent Server/v100500') ```
Author
Owner

@webknjaz commented on GitHub (Jun 24, 2017):

@werwolfby otherwise upgrade cheroot to v5.7.0, It's got normal string set by default now.

<!-- gh-comment-id:310862010 --> @webknjaz commented on GitHub (Jun 24, 2017): @werwolfby otherwise upgrade cheroot to `v5.7.0`, It's got normal string set by default now.
Author
Owner

@werwolfby commented on GitHub (Jun 28, 2017):

Cool, will do it.

<!-- gh-comment-id:311599503 --> @werwolfby commented on GitHub (Jun 28, 2017): Cool, will do it.
Author
Owner

@werwolfby commented on GitHub (Nov 23, 2019):

@webknjaz cause we've already updated to 6+ version of cheroot, I close the issue

<!-- gh-comment-id:557770662 --> @werwolfby commented on GitHub (Nov 23, 2019): @webknjaz cause we've already updated to 6+ version of cheroot, I close the issue
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
werwolfby/monitorrent#162
No description provided.