cree-py / pynite

Async python wrapper for the Fortnite API.
MIT License
10 stars 3 forks source link

Support for python 3.5 #3

Closed iElijahxD closed 6 years ago

iElijahxD commented 6 years ago

Issue running into

[22/02/2018 00:44] ERROR hydra on_command_error 390: Exception in command 'fortnite'
Traceback (most recent call last):
  File "lib/discord/ext/commands/core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/root/***/***/***/****.py", line 361, in fn_profile
    player = await self.fortnite.get_player(platform, name)
  File "/usr/lib/python3.5/site-packages/pynite/core.py", line 67, in get_player
    async with self.session.get('{API.PLAYER}/{platform}/{name}', timeout=self.timeout, headers=self.headers) as resp:
  File "lib/aiohttp/client.py", line 565, in __aenter__
    self._resp = yield from self._coro
  File "lib/aiohttp/client.py", line 195, in _request
    proxy=proxy, proxy_auth=proxy_auth, timeout=timeout)
  File "lib/aiohttp/client_reqrep.py", line 91, in __init__
    self.update_host(url)
  File "lib/aiohttp/client_reqrep.py", line 111, in update_host
    raise ValueError('Host could not be detected.')
ValueError: Host could not be detected.
umbresp commented 6 years ago

Pynite doesn’t support 3.5 for now. You can try updating python or wait a day or so while we fix comptablility issues.

SharpBit commented 6 years ago

He said he can do it, he's gonna open a pr, so I guess we can wait and see

iElijahxD commented 6 years ago

Problem is Fixed.. I'm not sure how to use github i'm kinda new to the site.. but if you want it to work for python3.5

these 2 changes need to be done.. first remove the import from .utils import API

then go to async def get_player(self, platform, name): don't use the pulling thing that is new to python use the old method

async def get_player(self, platform, name):
    platform = platform.lower()
    if platform not in ('xbl', 'psn', 'pc'):
        raise ValueError('Incorrect platform passed. Options: xbl, psn, pc')
    try:
        async with self.session.get('http://api.fortnitetracker.com/v1/profile/{}/{}'.format(platform,name), timeout=self.timeout, headers=self.headers) as resp:
            if resp.status == 200:
                raw_data = await resp.json()
                if raw_data.get('error'):
                    raise NotFound()
            elif 500 > resp.status > 400:
                raise Unauthorized()
            else:
                raise UnknownError()
    except asyncio.TimeoutError:
        raise NotResponding()

    data = Box(raw_data, camel_killer_box=True)
    player = Player(data, camel_killer_box=True)

    return player

this will fix the problem for python3.5 easily it took me 10mins to figure it out i didn't want to touch the code in the first place since i didn't have permission to do so but SharpBit granted me permission to fix it myself so i did

iElijahxD commented 6 years ago

And 1 more thing some string you guys using have f in the first before the start of the string for example f'bla' just remove the f

SharpBit commented 6 years ago

yes, and replace with .format(), do that for every single one, then go to https://github.com/cree-py/pynite/pulls to open one