KalleHallden / reddit_automations

318 stars 91 forks source link

from decouple import config #3

Open Pratham04 opened 4 years ago

Pratham04 commented 4 years ago

Bro in this project

import sys import subprocess import os from decouple import config

IP_NETWORK = config('IP_NETWORK') IP_DEVICE = config('IP_DEVICE')

I am getting this problrm:- from decouple import config ImportError: cannot import name 'config' from 'decouple' (C:\Python\python38-39\lib\site-packages\decouple__init__.py)

amnotyourbae commented 4 years ago

im also getting this problem:

Traceback (most recent call last): File "listen.py", line 6, in IP_NETWORK = config('IP_NETWORK') File "/Users/myname/.local/share/virtualenvs/listen_wifi-2NgIDSN5/lib/python3.8/site-packages/decouple.py", line 199, in call return self.config(*args, *kwargs) File "/Users/myname/.local/share/virtualenvs/listen_wifi-2NgIDSN5/lib/python3.8/site-packages/decouple.py", line 83, in call return self.get(args, **kwargs) File "/Users/myname/.local/share/virtualenvs/listen_wifi-2NgIDSN5/lib/python3.8/site-packages/decouple.py", line 68, in get raise UndefinedValueError('{} not found. Declare it as envvar or define a default value.'.format(option)) decouple.UndefinedValueError: IP_NETWORK not found. Declare it as envvar or define a default value.

cjoshmartin commented 4 years ago

I am also getting this error

cjoshmartin commented 4 years ago

@Pratham04 you installed the wrong pip package, install this one instead: https://pypi.org/project/python-decouple/

kartikeytewari commented 4 years ago

Decouple package from pip3 won't work, try installing python-decouple, for this script. For uninstalling decouple: pip3 uninstall decouple For installing python-decouple: pip3 install python-decouple

kartikeytewari commented 4 years ago

@amnotyourbae you will have to define the variables IP_NETWORK and IP_NETWORK in your .env file. Something line : IP_NETWORK = 192.168.54.255 IP_NETWORK = 192.168.54.65

Of course, the IP address will depend on your personal network. For a more comprehensive idea have a look at this script that I made: https://github.com/kartikeytewari/Netscanning

jimikaros commented 3 years ago

hello. How do we import the variables from the .env file? Is there a command?

kartikeytewari commented 3 years ago

No need, python will read from variables from .env file by itself. There is no need for different configurations.

jimikaros commented 3 years ago

thank you. that one is ok but I am finding very difficult to list all the IPs. I found the code below but for some reason it doesn't seem to list everything and I don't understand why. When I am logging into the router, there are several Android devices and smart plugs which are not listed with the code. I have been searching youtube and google for some time now but I haven't found it yet :( .

import os devices = [] for device in os.popen('arp -a'): devices.append(device)

for device in devices: print(device)

kartikeytewari commented 3 years ago

No need for the above code, your .env file should only have the variables. Getting your device IP (allocated by the router) should be possible by logging to your particular router, and accessing the information from there. The allocated IP can also be found in your particular device's settings.

HumbleYT commented 3 years ago

Guys how do you get / find the .env file???

kartikeytewari commented 3 years ago

you will have to make the .env file yourself!

batijo commented 3 years ago

@kartikeytewari I have no idea how you are able to get all your devices by pinging router. I've tried it both on my windows and linux machines and it always returns only IP the same device I was pinging in this case my router.

kartikeytewari commented 3 years ago

@Dzionys imo, your .env file might not be working properly. Share your .env file. I can then tell, if there is some issue with it. Also, I have made a better script that generated the ".env" file for yourself. To use that check out: https://github.com/kartikeytewari/Netscanning . Also, I in the .env file write your "local ip" not "public ip". For example to get local ip, in macos use the command: ipconfig getifaddr en0