PetterKraabol / Twitch-Python

Object-oriented Twitch API for Python developers
https://pypi.org/project/twitch-python
MIT License
214 stars 37 forks source link

400 Client Error: Bad Request for url #10

Closed ibLeDy closed 4 years ago

ibLeDy commented 4 years ago

I've been using Twitch-Python the same way for almost two months, this is the first time i face this issue. Seems a bit weird as it only happened this one time

helix = twitch.Helix(client_id=CLIENT_ID)
user_data = helix.users([user_name])[0]

user_name is always message.user.display_name.lower()

Traceback (most recent call last):
  File "/home/bledy/projects/barbota/barbota/twitch_chat.py", line 574, in check_user_exists
    user_data = helix.users([user_name])[0]
  File "/home/bledy/projects/barbota/.venv/lib/python3.7/site-packages/twitch/helix/helix.py", line 43, in users
    return helix.Users(self.api, *args)
  File "/home/bledy/projects/barbota/.venv/lib/python3.7/site-packages/twitch/helix/resources/users.py", line 49, in __init__
    for data in self._api.get(self._path, params=params, ignore_cache=True)['data']:
  File "/home/bledy/projects/barbota/.venv/lib/python3.7/site-packages/twitch/api.py", line 111, in get
    return self.request('GET', path, ignore_cache, params=params, headers=self._headers(headers), **kwargs)
  File "/home/bledy/projects/barbota/.venv/lib/python3.7/site-packages/twitch/api.py", line 100, in request
    response.raise_for_status()
  File "/home/bledy/projects/barbota/.venv/lib/python3.7/site-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://api.twitch.tv/helix/users?login=%E3%82%A8%E3%83%AD%E3%83%9D%E3%83%8B%E3%83%BC
PetterKraabol commented 4 years ago

I suppose the display name has non-latin letters. Use the user's login name instead of display name when calling the api.