'No Route To Host' error in installing 'NLTK Data' - python

I have been trying to install nltk.data for a project. As described in this documentation, I tried to install it using both methods mentioned.
Through python:
import nltk
nltk.download()
The problem is in the next step, ( please find the screenshot attached).
The error message is:
Packages:
Error connecting to server: [Errno 113] No route to host
Through command line:
sudo python -m nltk.downloader -d /usr/local/share/nltk_data
This resulted in the same issue too.
As mentioned in this answer, my DEFAULT_URL was https://raw.githubusercontent.com/nltk/nltk_data. Even after changing it to http://www.nltk.org/nltk_data/, I am getting the same problem.
Can anybody help, please?

Related

Python 3 does not recognize nmap module what am I doing wrong here?

Recently I have been learning python and I have just started a project making a nmap scanning script that will scan a network range for open ports. My only problem is that I have installed the nmap module but in my code, it says that the module does not have the attribute port scanner when I attempt to run it. I have looked around quite a bit for a solution and I have seen a lot of different solutions I will list what I have tried here.
First was to install python-nmap that didn't work
Next was to install the module nmap this didn't work either
I also heard you should uninstall nmap and install python-nmap instead this also did not work
Next It was suggested that since I am using python3 I should use pip3 to install python-nmap that didn't work either
Next I tried manually downloading and installing it and putting it in /lib/python3.7/dist-packages this didn't seem to do anything
I did notice that even though the installation did not fail on any of these methods only the manual install made it show up in the dist-packages folder and it still did not work after this. None of my versions of python have the nmap module inside of them. Does anyone know anything else that I should try to make this work? I am currently running a Debian 9 based os. thanks for your help in advance.
this is the error
Cannot find reference 'PortScanner' in '__Init__.py'
this is my code
import nmap
ns = nmap.PortScanner()
Basically you have to install nmap:
sudo apt-get install nmap
Then install python module:
sudo pip3 install -U python-nmap
After this you're good to go:
>>> import nmap
>>> nm = nmap.PortScanner()
>>> nm.scan('127.0.0.1', '22-443')
>>> nm.command_line()
'nmap -oX - -p 22-443 -sV 127.0.0.1'
>>> nm.scaninfo()
{'tcp': {'services': '22-443', 'method': 'connect'}}
>>> nm.all_hosts()
['127.0.0.1']
>>> nm['127.0.0.1'].hostname()
'localhost'
>>> nm['127.0.0.1'].state()
'up'
>>> nm['127.0.0.1'].all_protocols()
['tcp']
>>> nm['127.0.0.1']['tcp'].keys()
[80, 25, 443, 22, 111]

pyzabbix Zabbix sender

I am looking to send a few items to zabbix using Zabbix-Sender function of pyzabbix. As a test I am running the below code -
from pyzabbix import ZabbixMetric, ZabbixSender, ZabbixResponse
metrics = []
m= ZabbixMetric('mme01', 'TEST', 20)
metrics.append(m)
ZabbixSender('10.46.224.5').send(metrics)
I made this snippet after reading the document - https://py-zabbix.readthedocs.io/en/latest/sender.html
When I run the snippet I get the error -
AttributeError: 'ConnectionRefusedError' object has no attribute 'msg'
I have verified IP connectivity
Can Anyone help ?
there is a mess in modules names.
it seems you call 'other' pyzabbix module who has not needed methods.
first, remove all zabbix-related modules:
pip list | grep zabbix; pip uninstall ...
and then install pyzabbix:
pip install py-zabbix.
this should help.
UPDATED:
I dug deeper and figured out that the AttributeError: 'ConnectionRefusedError' object has no attribute 'msg' exception caused by old module version bug, which has been fixed here. update it with pip or manually.
new bug I have faced is [Errno 8] nodename nor servname provided, or not known caused by socket lib and can be fixed pointing to zabbix server/proxy IP address instead of DNS name
I decided to bypass the module - pyzabbix and decided to use the raw zabbix sender utility. Works great.
For other folks my solution relies on a file with values that need to be sent to zabbix.
Sample file -
"mme01" TEST 1544729668 44
The use the utility -
/opt/zabbix-proxy/bin/zabbix_sender -vv -z 10.43.X.X -T -i mme_file.txt
Replace with path of your zabbix_sender and the zabbix server IP.
I had the same issue on some machines of mine. At that time I refactored my code to use zabbix_sender and it worked great.
After some time I found out the issue was related to pip repository corruption. I ended up reinstalling all the packages with this option:
pip install --ignore-installed <package>
apparently the issue was fixed, but I still have no idea why it occurred on some manchines and not in anothers.

Invalid syntax python on iPhone

I got bored and was trying to install SET from trustedsec GitHub on my old Jailbroken iPhone 4S with iOS 8.4. I was getting an SSL certificate error.
So I used:
GIT_SSL_NO_VERIFY=true git clone https://github.com/trustedsec/social-engineer-toolkit set/
Which I was able to download the package.
Now when I go to install I get an invalid syntax error. I made sure I was in root.
To install I used.
iPhone:~ mobile$ cd set
iPhone:~/set mobile$ su
Password:
iPhone:/var/mobile/set root#
python setup.py install
Not sure what I'm doing wrong. Any help would be appreciated. I'm also a newb so be gentle . Sorry don't have enough points to post a picture, and couldn't copy and paste everything the code wasn't lining up properly so it wouldn't let me post the question.
File "setup.py", line 10
with
open(os.path.join(os.path.dirname
(__file__),
'pexpect', '__int__.py'), 'r') as f:
^
Syntax error: invalid syntax
picture of code <===========

OpenRAVE issue: E: Unable to find a source package for openrave

I try to use IKFast in my Baxter-Robot project. The last command from the baxter tutorial failed:
python /path_to_openrave/openrave/python/ikfast.py --robot=baxter_arm.right.rounded.dae --iktype=transform6d --baselink=1 --eelink=10 --freeindex=5 --savefile=baxter_right_arm_ikfast_solver.cpp
ERROR MESSAGE: /openrave/python/ikfast.py", line 9467, in
import openravepy ImportError: No module named openravepy
Because of that I follow the tutorial on openrave.org (http://openrave.org/docs/latest_stable/coreapihtml/installation_linux.html) for setting up OpenRave from the scratch. When I used the last command
sudo apt-get build-dep openrave
I got this message
E: Unable to find a source package for openrave
no idea why this happened...
My Qt version is 4.8.6, and gcc is 4.8.4, so that's no problem.
Thanks
Devel

error while trying to install a package using the python-apt API

I found a code which i need. It is from this link : How to install a package using the python-apt API
#!/usr/bin/env python
# aptinstall.py
import apt
import sys
pkg_name = "libjs-yui-doc"
cache = apt.cache.Cache()
cache.update() # error is in this line
pkg = cache[pkg_name]
if pkg.is_installed:
print "{pkg_name} already installed".format(pkg_name=pkg_name)
else:
pkg.mark_install()
try:
cache.commit()
except Exception, arg:
print >> sys.stderr, "Sorry, package installation failed [{err}]".format(err=str(arg))
However i can't make it work. I searched about the problem on the web. It is said that there should be no package manager,apt,pip etc active in order to work with this code. However, no package manager,apt,pip etc. is open in my computer. I thought that when computer starts, some package manager can be active. So i typed
ps -aux
in terminal and look at the active processes, but i didn't see any active process related to package manager(i'm not %100 sure about this, because any process i don't know can be related to package manager.But how could i know it?) To sum up,i started the computer and opened only terminal. Then i typed python aptinstall.py and hit enter. I take the following error :
Traceback (most recent call last):
File "aptinstall.py", line 7, in <module>
cache.update()
File "/usr/lib/python2.7/dist-packages/apt/cache.py", line 397, in update
raise LockFailedException("Failed to lock %s" % lockfile)
apt.cache.LockFailedException: Failed to lock /var/lib/apt/lists/lock
I delete the lock by giving the command in terminal :
sudo rm /var/lib/dpkg/lock
It didn't work too.
How can i solve this problem? Any idea will be appreciated.
Please try looking for update-manager in ps. It runs automatically on a periodic basis, so it may be locking the apt db.
There are three different reasons which cause this error.
1 - As i mentioned earlier, if any package manager is runnning(for example;pip,apt-get,synaptic,etc), it gives the error.
2 - If you are using your ubuntu in a virtual machine, this causes the same error.
3 - If you are running your program without root privileges, this causes the same error. For example ,if you are running your program with "python aptinstall.py" you get the error, running the program with "sudo python aptinstall.py" is the correct one.

Categories

Resources