# Проблема с умлаутами при встраивании Discourse на другой сайт

**URL:** <https://meta.discourse.org/t/problem-with-umlauts-when-embedding-discourse-on-another-website/288171>\
**Category:** Product Support\
**Tags:** embedding\
**Created:** [10.Декабрь.2023 21:41:29 UTC](https://meta.discourse.org/t/problem-with-umlauts-when-embedding-discourse-on-another-website/288171 "2023-12-10T21:41:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)\
**Post date:** [11.Декабрь.2023 05:08:05 UTC](https://meta.discourse.org/t/problem-with-umlauts-when-embedding-discourse-on-another-website/288171/2 "2023-12-11T05:08:05Z")

</div>

> [@limetti](#):
>
> Заголовки вроде «Ich würde» превращаются в «Ich wÃ¼rd

Это классическая проблема «неверной кодировки».

В качестве примера: если мы прочитаем (например, через Python) необработанные данные из вашего поста:

```plaintext
In [1]: import urllib

In [2]: u = urllib.request.urlopen('https://meta.discourse.org/posts/1418409/raw')

In [3]: r = u.read(); r
Out[3]: b'As described here (https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963/453), when embedding Discourse into my website, the title is correctly parsed. But as it contains umlauts, titles like \xe2\x80\x9cIch w\xc3\xbcrde\xe2\x80\x9d end up in \xe2\x80\x9cIch w\xc3\x83\xc2\xbcrde\xe2\x80\x9d.\n\nIs this a general problem, a problem with my page or any workaround for that? Thanks!'

```

Мы получаем _байты_, но не знаем, как их декодировать. Однако один из заголовков ответа указывает, что следует использовать UTF-8:

```plaintext
In [4]: u.headers['content-type']
Out[4]: 'text/plain; charset=utf-8'

In [5]: r.decode('utf-8')
Out[5]: 'As described here (https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963/453), when embedding Discourse into my website, the title is correctly parsed. But as it contains umlauts, titles like "Ich würde" end up in "Ich wÃ¼rde".\n\nIs this a general problem, a problem with my page or any workaround for that? Thanks!'

In [6]: print(r.decode('utf-8'))
As described here (https://meta.discourse.org/t/embed-discourse-comments-on-another-website-via-javascript/31963/453), when embedding Discourse into my website, the title is correctly parsed. But as it contains umlauts, titles like "Ich würde" end up in "Ich wÃ¼rde".

Is this a general problem, a problem with my page or any workaround for that? Thanks!

```

Обратите внимание, что символы выглядят точно так же, как вы их опубликовали. Но когда эти байты интерпретируются неверно — особенно при распространённой ошибке интерпретации этих байтов как [ISO-8859-1](https://en.wikipedia.org/wiki/ISO/IEC_8859-1) вместо [UTF-8](https://en.wikipedia.org/wiki/UTF-8) (ниже приведён сокращённый фрагмент строки для наглядности), получается:

```plaintext
In [7]: snippet = r[220:255]; snippet
Out[7]: b'titles like \xe2\x80\x9cIch w\xc3\xbcrde\xe2\x80\x9d end up'

In [8]: snippet.decode('utf-8')
Out[8]: 'titles like "Ich würde" end up'

In [9]: snippet.decode('iso-8859-1')
Out[9]: 'titles like â\x80\x9cIch wÃ¼rdeâ\x80\x9d end up'

```

Если я выполню `print` для этого, мой терминал зависнет. Удивительно. 😃

Подводя итог: что бы вы ни использовали для извлечения данных поста из Discourse, оно трактует их как iso-8859-1 вместо utf-8.

(предположительно) Возможно, вы встраиваете необработанные байты, полученные с сайта Discourse, на страницу, которая отдаётся с кодировкой iso-8859-1.

---

_[View the full topic](https://meta.discourse.org/t/problem-with-umlauts-when-embedding-discourse-on-another-website/288171)._
