Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Ossapi.__init__() got an unexpected keyword argument 'headers' #57

Closed
Arthurfogo7 opened this issue Mar 20, 2023 · 6 comments

Comments

@Arthurfogo7
Copy link

Arthurfogo7 commented Mar 20, 2023

I'm trying to get information from a beatmap using my api key, but this error keeps happening, what I'm doing wrong?

import ossapi

Replace "YOUR_API_KEY" with your own API key

api_key = "My api key"

Create a dictionary of headers to set the user agent

headers = {"User-Agent": "MyAwesomeApp/1.0"}

Create an Ossapi object using your API key and headers

api = ossapi.Ossapi(api_key, headers=headers)

Replace "BEATMAP_ID" with the ID of the beatmap you want to get information for

beatmap_id = "1514385"

Get the beatmap information using the get_beatmaps method

The method returns a list of beatmap objects, so we access the first item in the list

beatmap = api.get_beatmaps(beatmap_id=beatmap_id)[0]

Open a text file for writing

filename = f"{beatmap_id}.txt" # Use the beatmap ID as the filename
with open(filename, "w") as f:

# Write the beatmap information to the file
f.write(f"Title: {beatmap.title}\n")
f.write(f"Artist: {beatmap.artist}\n")
f.write(f"Creator: {beatmap.creator}\n")
f.write(f"Difficulty name: {beatmap.version}\n")
f.write(f"Stars: {beatmap.difficulty_rating}\n")
f.write(f"Circle size: {beatmap.circle_size}\n")
f.write(f"Overall difficulty: {beatmap.overall_difficulty}\n")
f.write(f"Approach rate: {beatmap.approach_rate}\n")
f.write(f"HP drain: {beatmap.hp_drain}\n")
f.write(f"Max combo: {beatmap.max_combo}\n")
f.write(f"Length (in seconds): {beatmap.total_length}\n")
f.write(f"BPM: {beatmap.bpm}\n")
f.write(f"Source: {beatmap.source}\n")
f.write(f"Tags: {beatmap.tags}\n")
f.write(f"Download link: {beatmap.download_link}\n")

print(f"Beatmap information written to {filename}")

@tybug
Copy link
Owner

tybug commented Mar 20, 2023

ossapi doesn't require a custom user agent and has no headers parameter, so you should only pass the api key:

api = ossapi.Ossapi(api_key)

I'm not sure why you're specifying a user agent, but you don't have to for the osu! api.

@Arthurfogo7
Copy link
Author

image
TypeError: Ossapi.init() missing 1 required positional argument: 'client_secret'

How can I use this argument?

@tybug
Copy link
Owner

tybug commented Mar 20, 2023

If you're using ossapi v3.0.0 or later (which it seems like you are), then the v1 version of ossapi is called ossapi.OssapiV1 and the v2 version is called ossapi.Ossapi, so you should do the following:

api = ossapi.OssapiV1(api_key)

If you want to use v2 of the api, you'll have to follow the instructions here to create an ouath client: https://circleguard.github.io/ossapi/creating-a-client.html.

@Arthurfogo7
Copy link
Author

File "c:\Users\arthu\Codes\import osuapi.py", line 14, in
beatmap = api.get_beatmaps(beatmap_id=beatmap_id)[0]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

Sorry for troubling, but this error happened. What item is outside the index range?

@tybug
Copy link
Owner

tybug commented Mar 20, 2023

what is beatmap_id? If it's 1514385 as in your screenshot above, then that beatmap doesn't exist: https://osu.ppy.sh/b/1514385. You're probably using the beatmapset id. You need to use the beatmap id. In this case, either 3111191 or 3100537 depending on the difficulty you want.

@Arthurfogo7
Copy link
Author

Oh, I didn't know there was two types of ID, thank you!

@tybug tybug closed this as completed Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants