Unicode 用户名

您在使用什么?这个错误看起来像 Python?这得到了 requests 的支持,但可能不是您正在使用的库的支持。

In [1]: import requests

In [2]: api_key = '«redacted»'

In [3]: r = requests.get('https://try.discourse.org/u/运思/notifications.json', headers = {
  'api-key': api_key,
  'api-username': '运思'.encode()
})

In [4]: r.status_code
Out[4]: 200

In [5]: r.json()['users'][0]
Out[5]:
{'id': 41,
 'username': '运思',
 'name': 'Michael Brown',
 'avatar_template': '/user_avatar/try.discourse.org/运思/{size}/208_2.png',
 'trust_level': 1,
 'assign_icon': 'user-plus',
 'assign_path': '/u/运思/activity/assigned'}

尝试调用 .encode() 来显式地将标头值转换为 bytes……尽管不可否认,由于并非所有内容都是 8 位干净的,我确实同意这个建议:

是合理的。