# 与SSO和 '~' 字符有关的问题

**URL:** https://meta.discourse.org/t/issues-with-sso-and-character/351582
**Category:** Support
**Created:** [2025年二月11日 03:28 UTC](https://meta.discourse.org/t/issues-with-sso-and-character/351582 "2025-02-11T03:28:44Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2025年二月11日 10:43 UTC](https://meta.discourse.org/t/issues-with-sso-and-character/351582/8 "2025-02-11T10:43:40Z")

</div>

> [@sweetbeems](#):
>
> 这是我的编码 Python 实现：
> 
> ```plaintext
> return_payload = base64.urlsafe_b64encode(parse.urlencode(params).encode())
> 
> ```

看起来 `urlsafe_b64encode` 替换了 base64 编码中的一些字符。来自[文档](https://docs.python.org/3/library/base64.html#base64.urlsafe_b64encode)：

> 使用 URL 和文件系统安全字母表对 [bytes-like object](https://docs.python.org/3/glossary.html#term-bytes-like-object) _s_ 进行编码，该字母表在标准 Base64 字母表中用 `-` 替换 `+`，用 `_` 替换 `/`，并返回编码后的 [`bytes`](https://docs.python.org/3/library/stdtypes.html#bytes)。结果仍然可能包含 `=`。

这意味着结果不是标准的 base64，并且与 Discourse 的解码不兼容。

我建议改用普通的 `b64encode` 函数。如果需要，您的 HTTP 库应能处理 URL 转义。

---

_[View the full topic](https://meta.discourse.org/t/issues-with-sso-and-character/351582)._
