# Unicode usernames

**URL:** <https://meta.discourse.org/t/unicode-usernames/277878>\
**Category:** Development\
**Tags:** rest-api\
**Created:** [September 5, 2023, 4:50pm UTC](https://meta.discourse.org/t/unicode-usernames/277878 "2023-09-05T16:50:44Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![hawm](https://avatars.discourse-cdn.com/v4/letter/h/f07891/32.png) [@hawm](https://meta.discourse.org/u/hawm)\
**Post date:** [September 10, 2023, 3:14pm UTC](https://meta.discourse.org/t/unicode-usernames/277878/18 "2023-09-10T15:14:37Z")

</div>

I can confirmed that below example would work:

```plaintext
$ curl -s -L \
-H 'api-key: 60834ccb8eda28cf17bab8efbbb2fbf874eb8b5a75ff17ddbd2346eb292881a0' \
-H 'api-username: 测试用户' \
http://localhost:4200/u/%E6%B5%8B%E8%AF%95%E7%94%A8%E6%88%B7/emails.json

{"email":"discobot_email","secondary_emails":[],"unconfirmed_emails":[],"associated_accounts":[]}

```

And without `api-*` header:

```plaintext
$ curl -s -L \
http://localhost:4200/u/%E6%B5%8B%E8%AF%95%E7%94%A8%E6%88%B7/emails.json

{"errors":["You need to be logged in to do that."],"error_type":"not_logged_in"}

```

Python requests example:

```plaintext
import requests

api_key = '60834ccb8eda28cf17bab8efbbb2fbf874eb8b5a75ff17ddbd2346eb292881a0'
api_username = '测试用户'
api_endpoint = 'http://localhost:4200/u/%E6%B5%8B%E8%AF%95%E7%94%A8%E6%88%B7/emails.json'

r = requests.get(api_endpoint, headers={
                 'api-key': api_key, 'api-username': api_username.encode()})

print(r)

<Response [200]>

```

> [@zengyunsi](#):
>
> ```plaintext
> Api-Username: \xe9\xa3\x8e\xe4\xb9\x8b\xe6\x97\x85\xe4\xba\xba
> 
> ```

Seems your `api-username` does not encode appropriately

```plaintext
>>> '风之旅人'.encode()
b'\xe9\xa3\x8e\xe4\xb9\x8b\xe6\x97\x85\xe4\xba\xba'

```

> <https://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal>

---

_[View the full topic](https://meta.discourse.org/t/unicode-usernames/277878)._
