Code Monkey home page Code Monkey logo

valclient.py's Introduction

valclient.py

API wrapper for VALORANT's client API

Discord Downloads

Installation

pip install valclient

Example

from valclient.client import Client

client = Client(region="na")
client.activate()

# get MatchID of latest match
history = client.fetch_match_history(queue_id="unrated")
print(history["History"][0]["MatchID"])

Notes

  • don't use this to make anything that's obviously against TOS (i.e. automatic agent selecting program)
  • just don't be dumb :)

Docs

Check out Techdoodle's extensive documentation. Most of the endpoints are implemented in this wrapper, but if you find another one/I'm missing one, open an issue!

valclient.py's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

valclient.py's Issues

Pre-game api issue

tldr.
It says that you are not in a pre-game in pregame_fetch_match while the pregame_fetch_player returns a MatchId. Can you help?

The following code

print(self.client.fetch_presence())
print(self.client.pregame_fetch_player())
match_id = self.client.pregame_fetch_player()
match = self.client.pregame_fetch_match(match_id) # The line which triggered the error


Gives this as a result


{'isValid': True, 'sessionLoopState': 'PREGAME', 'partyOwnerSessionLoopState': 'PREGAME', 'customGameName': '', 'customGameTeam': '', 'partyOwnerMatchMap': '/Game/Maps/Port/Port', 'partyOwnerMatchCurrentTeam': '', 'partyOwnerMatchScoreAllyTeam': 0, 'partyOwnerMatchScoreEnemyTeam': 0, 'partyOwnerProvisioningFlow': 'Matchmaking', 'provisioningFlow': 'Matchmaking', 'matchMap': '/Game/Maps/Port/Port', 'partyId': 'blablabla', 'isPartyOwner': True, 'partyState': 'DEFAULT', 'partyAccessibility': 'CLOSED', 'maxPartySize': 5, 'queueId': 'spikerush', 'partyLFM': False, 'partyClientVersion': 'release-03.08-shipping-5-620887', 'partySize': 1, 'tournamentId': '', 'rosterId': '', 'partyVersion': 1634747847209, 'queueEntryTime': '2021.10.20-16.37.25', 'playerCardId': 'blablabla', 'playerTitleId': 'blablabla', 'preferredLevelBorderId': '', 'accountLevel': 28, 'competitiveTier': 4, 'leaderboardPosition': 0, 'isIdle': False}

{'Subject': 'blablabla', 'MatchID': 'eb6df31c-bf10-4561-8a83-d44db1ebf963', 'Version': 1634747847163}

---------------------------------------------------------------------------
PhaseError                                Traceback (most recent call last)
C:\Users\REBELL~1\AppData\Local\Temp/ipykernel_12588/4048721659.py in <module>
      2 
      3 program = Program(user_id)
----> 4 program.run()

C:\Users\REBELL~1\AppData\Local\Temp/ipykernel_12588/2252940000.py in run(self)
     49         match_id = self.client.pregame_fetch_player()
     50         print(match_id)
---> 51         match = self.client.pregame_fetch_match(match_id)
     52         print(match)
     53 

~\Documents\projects\valclient\src\valclient\client.py in pregame_fetch_match(self, match_id)
    609         '''
    610         match_id = self.__pregame_check_match_id(match_id)
--> 611         data = self.fetch(endpoint=f"/pregame/v1/matches/{match_id}",endpoint_type="glz", exceptions={404: [PhaseError, "You are not in a pre-game"]})
    612         return data
    613 

~\Documents\projects\valclient\src\valclient\client.py in fetch(self, endpoint, endpoint_type, exceptions)
     99 
    100             # custom exceptions for http status codes
--> 101             self.__verify_status_code(response.status_code, exceptions)
    102 
    103             try:

~\Documents\projects\valclient\src\valclient\client.py in __verify_status_code(self, status_code, exceptions)
     91         if status_code in exceptions.keys():
     92             response_exception = exceptions[status_code]
---> 93             raise response_exception[0](response_exception[1])
     94 
     95     def fetch(self, endpoint="/", endpoint_type="pd", exceptions={}) -> dict: # exception: code: {Exception, Message}

PhaseError: You are not in a pre-game

Fetch Leaderboard Region Issue

def fetch_leaderboard(self, season:str, start_index:int=0, size:int=25) -> dict:
        '''
        MMR_FetchLeaderboard
        Get the competitive leaderboard for a given season
        The query parameter query can be added to search for a username.
        '''
        if season == "": season = self.__get_live_season()
        data = self.fetch(f"/mmr/v1/leaderboards/affinity/na/queue/competitive/season/{season}?startIndex={start_index}&size={size}", endpoint_type="pd")
        return data

it should be change to:

def fetch_leaderboard(self, season:str, start_index:int=0, size:int=25) -> dict:
        '''
        MMR_FetchLeaderboard
        Get the competitive leaderboard for a given season
        The query parameter query can be added to search for a username.
        '''
        if season == "": season = self.__get_live_season()
        data = self.fetch(f"/mmr/v1/leaderboards/affinity/{shard}/queue/competitive/season/{season}?startIndex={start_index}&size={size}", endpoint_type="pd")
        return data

Several client "fetch" functions returning None

I've noticed that some of the functions are returning None - perhaps the API path has changed? Namely the following:

contracts_fetch_active_story
contracts_fetch_definitions
fetch_player_restrictions

I didn't check all the client functions though, these are just the ones I came across. I am only able to test in NA.

I've tried looking for updated documentation on these APIs - there's a few other github pages that came up, but none of them worked.

Steps to repro:

  1. Run VALORANT.
  2. Run the following:
from valclient import Client

client = Client(region="na")
client.activate()

print(client.contracts_fetch_active_story())
print(client.contracts_fetch_definitions())
print(client.fetch_player_restrictions())

Wrong Leave Party Url

def party_leave(self, party_id:str) -> dict:
        '''
        Party_PlayerLeave
        Leave a party
        '''
        data = self.post(endpoint=f"/parties/v1/players/{self.puuid}/joinparty/{party_id}",endpoint_type="glz")
        return data

Correct one: "/parties/v1/players/{self.puuid}/leaveparty/{party_id}"

fetch(), contracts_fetch() and fetch_content() returning None

Since VALORANT 6.01, I've been seeing these two client calls returning None. Running the following with the game open

from valclient import Client
import requests

client = Client()
client.activate()

print(client.fetch_content())
print(client.contracts_fetch())

response1 = requests.get(f"https://pd.na.a.pvp.net/contracts/v1/contracts/{client.puuid}", headers=client.headers)
print(response1.text)
response2 = requests.get(f"https://shared.na.a.pvp.net/content-service/v3/content", headers=client.headers)
print(response2.text)

gives

None
None
{"httpStatus":500,"errorCode":"INTERNAL_UNHANDLED_SERVER_ERROR","message":"Unexpected error encountered"}

{"httpStatus":500,"errorCode":"INTERNAL_SERVER_ERROR","message":"Internal error encountered"}

That said, I inspected ShooterGame.log, and it looks like the endpoints and API routes are correct (unlike in a previous issue where the API got bumped from v2 to v3). Moreover, I can see successful calls in the log to these endpoints:

...
[2023.01.19-01.41.38:877][928]LogPlatformCommon: Platform HTTP Query End. QueryName: [Contracts_Fetch], URL [GET https://pd.na.a.pvp.net/contracts/v1/contracts/ac0fd66f-cab6-5079-a4e8-66e9be0742a6], TraceID: [8441B8F442CE3D824F2CBCA41411DABF] Response Code: [200]
...
...
[2023.01.19-01.43.40:043][ 86]LogPlatformCommon: Platform HTTP Query End. QueryName: [Content_FetchContent], URL [GET https://shared.na.a.pvp.net/content-service/v3/content], TraceID: [EF8E97F046669DD978F0F985870C7846] Response Code: [200]
...

So I'm thinking maybe something has changed with the API interaction = maybe additional or different parameters/headers are required. Let me know if you can reproduce this with the latest version of VALORANT.

Authentication with accounts other than local

import valclient

client = valclient.Client(region="eu", auth={
    "username":"myusername","password":"mypass"
})
client.activate()

I keep getting valclient.exceptions.HandshakeError: Unable to activate; is VALORANT running?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.