isFakeAccount / psnawp

PlayStation Network API Python
https://pypi.org/project/PSNAWP/
Other
110 stars 23 forks source link

PSNAWPNotFound from a TrophyIterator on PS5 games #72

Closed Frygidairus closed 5 months ago

Frygidairus commented 5 months ago

Hello, I am currently trying to use PSNAWP 2.0.0 to retrieve my trophies from the last title I played.

Unfortunately, I am no able to get the trophies for PS5 titles. The TrophyIterator returned by the method User.trophies() greets me with an error 404 as soon as I try to iterate over it. This error could be raised in the case I have no trophy for this title, yet I have quite a few of those... For PS4 games, I am able to iterate without any issue.

Here is a code sample to illustrate what I mean:

from psnawp_api import PSNAWP

client = PSNAWP(NPSSO)

user = client.user(online_id="Frygidairus")

#Trophies from Burnout Paradise
trophies = user.trophies(
    'NPWR14842_00',
    'PS4'
)
print(next(trophies))

#Trophies from Diablo IV
trophies = user.trophies(
    'NPWR22810_00',
    'PS5'
)
print(next(trophies))

Here is the result when running the script:

Trophy(trophy_set_version='01.00', has_trophy_groups=True, trophy_id=0, trophy_hidden=False, trophy_type=<TrophyType.PLATINUM: 'platinum'>, trophy_name='Burnout Paradise Elite', trophy_detail='Awarded for successfully collecting all trophies from Burnout Paradise', trophy_icon_url='https://image.api.playstation.com/trophy/np/NPWR14842_00_007326ECF7B78940E23D1587323910E816F1620087/3974A04727EA169D039B773C21E5DD24D907218C.PNG', trophy_group_id='default', trophy_progress_target_value=None, trophy_reward_name=None, trophy_reward_img_url=None)

Traceback (most recent call last):
  File "/Users/gde/greeter/testest.py", line 21, in <module>
    print(next(trophies))

  File "/Users/gde/greeter/venv/lib/python3.10/site-packages/psnawp_api/models/listing/pagination_iterator.py", line 45, in __next__
    return self.__iterator.__next__()

  File "/Users/gde/greeter/venv/lib/python3.10/site-packages/psnawp_api/models/trophies/trophy.py", line 157, in fetch_next_page
    response = self.authenticator.get(url=self._url, params=params).json()

  File "/Users/gde/greeter/venv/lib/python3.10/site-packages/psnawp_api/core/authenticator.py", line 34, in _impl
    method_out = method(*method_args, **method_kwargs)

  File "/Users/gde/greeter/venv/lib/python3.10/site-packages/psnawp_api/core/authenticator.py", line 283, in get
    return self.request_builder.get(**kwargs)

  File "/Users/gde/greeter/venv/lib/python3.10/site-packages/psnawp_api/core/request_builder.py", line 143, in get
    return self.request(method="get", **kwargs)

  File "/Users/gde/greeter/venv/lib/python3.10/site-packages/psnawp_api/core/request_builder.py", line 122, in request
    response_checker(response)

  File "/Users/gde/greeter/venv/lib/python3.10/site-packages/psnawp_api/core/request_builder.py", line 47, in response_checker
    raise PSNAWPNotFound(response.text)

psnawp_api.core.psnawp_exceptions.PSNAWPNotFound: {"error":{"referenceId":"5e2a3823-2ce6-11ef-80fc-adb49a3fbf8c","code":2240525,"message":"Resource not found"}}

As you can see, the TrophyIterator for the PS4 game return the first trophy of the list, but the PS5 TrophyIterator raises an error.

I have a hard time understanding why since I had no issue with the previous version of PSNAWP. I am trying to pin point what is happening, I will keep you updated if I find something!

Frygidairus commented 5 months ago

Note that I tested this on several PS5 and PS4 games, with similar results

Frygidairus commented 5 months ago

I was able to query the endpoints directly thanks to my bearer token, resulting in 200 HTTP status codes. Both the trophy set and the progress set were retrieved thanks to the Postman queries as per the screenshots. I have yet to understand what goes wrong... image image

isFakeAccount commented 5 months ago

@Frygidairus

Can you try with the latest version of PSNAWP because it works for me.

image

Also, assuming if you are looking up your own trophies you can use the client class

from psnawp_api import PSNAWP
from psnawp_api.models.trophies import PlatformType

client = psn.me()
trophies = client.trophies("NPWR22810_00", PlatformType.PS5)
print(next(trophies))

This will save you some extra HTTP requests.

isFakeAccount commented 5 months ago

I think I might know the issue. I switch platform type from string to Enum and passing in enum threw off the API wrapper.

default case is for PS4 so which it is why it worked. but PS5 didn't

isFakeAccount commented 5 months ago

image

Yup, I get the same error when string is passed.

Frygidairus commented 5 months ago

I just tested it too, and indeed, getting rid of the string fixed it! Thank you so much :)