Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError
#1
TypeError: __init__() missing 2 required positional argument: 'loop' and 'session'
Reply
#2
Ok? Why aren't you passing those values to __init__ then? Note that showing your code would probably help.
Reply
#3
i cant show my code because it contains an IP address and it the pihole plugin that is passing to __init__
Reply
#4
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.
Reply
#5
import pihole as ph
pihole = ph.pihole('IP_Of_Pihole')
Reply
#6
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?
Reply
#7
the code i sent worked and then stopped working and that how it says to use it at https://pypi.org/project/PiHole-api/
Reply
#8
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?
Reply
#9
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020