Python Forum
TypeError - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: TypeError (/thread-26894.html)



TypeError - kcajminer2312 - May-17-2020

TypeError: __init__() missing 2 required positional argument: 'loop' and 'session'


RE: TypeError - ndc85430 - May-17-2020

Ok? Why aren't you passing those values to __init__ then? Note that showing your code would probably help.


RE: TypeError - kcajminer2312 - May-17-2020

i cant show my code because it contains an IP address and it the pihole plugin that is passing to __init__


RE: TypeError - deanhystad - May-17-2020

If you want help you really need to provide code. It doesn't have to be THE CODE. In fact it is better if it is not THE CODE, but rather something that is shorter but still exhibits the same problem.


RE: TypeError - kcajminer2312 - May-17-2020

import pihole as ph
pihole = ph.pihole('IP_Of_Pihole')


RE: TypeError - deanhystad - May-17-2020

The example.py for pihole shows it used this way:
import asyncio
import json
import aiohttp
from pihole import PiHole

async def main():
    """Get the data from a Pi-hole instance."""
    async with aiohttp.ClientSession() as session:
        data = PiHole('192.168.0.215', loop, session)
        await data.get_data()

        # Get the raw data
        print(json.dumps(data.data, indent=4, sort_keys=True))
        print("Status:", data.status)
        print("Domains being blocked:", data.domains_being_blocked)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
Where is your loop and session?


RE: TypeError - kcajminer2312 - May-17-2020

the code i sent worked and then stopped working and that how it says to use it at https://pypi.org/project/PiHole-api/


RE: TypeError - deanhystad - May-17-2020

Ok, grabbed the code from GitHub
class PiHole(object):
    <snip>
    # Takes in an ip address of a pihole server
    def __init__(self, ip_address):
        self.ip_address = ip_address
        self.auth_data = None
        self.refresh()
        self.pw = None
The example.py must be some older version. Now I am confused about why you didn't get an error complaining about not finding ph.pyhole since the class is named PyHole. Very interesting that your original post mentions not providing arguments for loop and session. Are you having problems running your program on some machines but not others? Is there a pihole version skew problem?


RE: TypeError - kcajminer2312 - May-17-2020

it only happens on the raspberry pi, i have just tested it, in need it to run on the raspberry pi as it is linked to a breadboard

i had re-install pihole not pihole-api, all works now