frissyn / valorant.py

Complete Python interface for the Valorant API. Works right out of the box!
https://valorantpy.readthedocs.io
MIT License
125 stars 19 forks source link

get_leaderboard timeout #41

Closed musnows closed 2 years ago

musnows commented 2 years ago
async def lead123(msg: Message):
    client = valorant.Client(KEY, region="jp")
    lb = client.get_leaderboard(size=15)
    print("Top Players in EU:\n")
    # Print all players on the leaderboard.
    for p in lb.players:
        print(f"#{p.leaderboardRank} - {p.gameName} ({p.numberOfWins} wins)")

I'm using this command for a bot,but err occurred like this region="eu" also time out.Is this a normal Internet connection err? my api key isn't invalid

error handling command: lead
Traceback (most recent call last):
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\util\connection.py", line 72, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\socket.py", line 955, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py", line 1040, in _validate_conn
    conn.connect()
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000029608D670A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\adapters.py", 
line 489, in send
    resp = conn.urlopen(
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\connectionpool.py", line 785, in urlopen
    retries = retries.increment(
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='jp.api.riotgames.com', port=443): Max retries exceeded with url: /val/content/v1/contents?locale=zh-CN (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000029608D670A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))    

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\khl\command\command.py", line 87, in handle
    await self.execute(msg, *args)
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\khl\command\command.py", line 119, in execute
    await self.handler(*args)
  File "C:\Clone_Gitee\Valorant-kaiheila-bot\code\main.py", line 137, in lead
    await lead123(msg)
  File "C:\Clone_Gitee\Valorant-kaiheila-bot\code\val.py", line 50, in lead123
    client = valorant.Client(KEY, region="jp")
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\valorant\client.py", line 72, in __init__
    self.get_content(cache=True)
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\valorant\client.py", line 178, in get_content
    content = self._content_if_cache()
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\valorant\client.py", line 80, in _content_if_cache
    return ContentDTO(self.handle.call("GET", "content"))
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\valorant\caller.py", line 52, in call
    r = self.sess.request(m, url, params=params)
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\sessions.py", 
line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\sessions.py", 
line 701, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\m\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\requests\adapters.py", 
line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='jp.api.riotgames.com', port=443): Max retries exceeded with url: /val/content/v1/contents?locale=zh-CN (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000029608D670A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed')) 

And this function works well

client = valorant.Client(KEY, locale=None)
lb = client.get_leaderboard(size=100)

# Find all the players on the leaderboard with 10 wins.
# `.find_all` is an alias for `.get_all`, provided for semantics.
players = lb.players.get_all(numberOfWins=10)

for p in lb.players:
    print(f"#{p.leaderboardRank} - {p.gameName} ({p.numberOfWins} wins)")
musnows commented 2 years ago

I found out that if I set a region.It will return a err

musnows commented 2 years ago

now it works well,I don't know why

client = valorant.Client(KEY, locale=None,region='ap',route='asia')
        lb = client.get_leaderboard(size=sz)
        players = lb.players.get_all(numberOfWins=num)
        cm = CardMessage()
        for p in lb.players:
            c1.append(Module.Section(f"#{p.leaderboardRank} - {p.gameName} ({p.numberOfWins} wins)"))
            #print(f"#{p.leaderboardRank} - {p.gameName} ({p.numberOfWins} wins)")
        cm.append(c1)
        await msg.reply(cm)