How to install Python packages over SSH Port Forwarding? - python

I am controlling a remote unit over SSH and OPENVPN.
On the remote unit I want to install some Python packages using pip but:
the remote company firewall allows only traffic on port 22 (and not 443, needed by pip);
DNS is not installed on the remote unit;
I cannot modify any OPENVPN settings (or I would like to avoid this option as it means to access some remote sysadmin and try to convince him that the configuration must be changed);
all systems are Linux (Ubuntu + Debian). Non Windows involved.
Stripping down hours of attempts (I am not a system admin and my knowledge on this subject is very limited), the idea was to open an obvious SSH port forwarding:
ssh -R 9999:pypi.python.org:443 xxxx#XX.XX.XX.XX
and then, on the remote unit play with pip install:
pip install pymodbus==1.3.2 --proxy localhost:9999
But this command returns:
Cannot fetch index base URL https://pypi.python.org/simple/
Could not find any downloads that satisfy the requirement pymodbus==1.3.2
/root/.pip/pip.log is:
Getting page https://pypi.python.org/simple/pymodbus/
Could not fetch URL https://pypi.python.org/simple/pymodbus/: connection error: ('Connection aborted.', BadStatusLine("''",))
Will skip URL https://pypi.python.org/simple/pymodbus/ when looking for download links for pymodbus==1.3.2
Getting page https://pypi.python.org/simple/
Could not fetch URL https://pypi.python.org/simple/: connection error: ('Connection aborted.', BadStatusLine("''",))
Will skip URL https://pypi.python.org/simple/ when looking for download links for pymodbus==1.3.2
Cannot fetch index base URL https://pypi.python.org/simple/
URLs to search for versions for pymodbus==1.3.2:
* https://pypi.python.org/simple/pymodbus/1.3.2
* https://pypi.python.org/simple/pymodbus/
Getting page https://pypi.python.org/simple/pymodbus/1.3.2
Could not fetch URL https://pypi.python.org/simple/pymodbus/1.3.2: connection error: ('Connection aborted.', BadStatusLine("''",))
Will skip URL https://pypi.python.org/simple/pymodbus/1.3.2 when looking for download links for pymodbus==1.3.2
Getting page https://pypi.python.org/simple/pymodbus/
It is obvious the remote unit cannot read the index page on pypi.pthon.org because the connection is refused.
What is the correct syntax for what I am trying to achieve?

Proxy is going to be tricky. I suggest that you scp the pip module source file and install it locally from source. Use
pip install package —download="/pth/to/downloaded/file” to get the package, scp it to the dest server and use pip install “/pth/to/scp/file”

It's look like my problem. after exploration, I have found a solution.
And because in my region, pypi.python.org is slow, so I change my pip.conf and use pypi.douban.com/simple, as my index-url. this website use http protocol. so in my solution. I use 80 port as my target port.
Problem:
I have two host. host1 could connect Pypi.douban.com. and host2 couldn't.
but I can connect host2 in host1 through ssh.
so in host2, I open a tmux session and open a ssh tunnel by local port forwarding(not remote port forwarding):
ssh -L 9999:pypi.douban.com:80 username#host1
after this redirect, I can use
pip install scikit-learn --proxy localhost:9999
to install package in host2.

Related

Connecting to Elasticsearch via python

I am running elasticsearch-8.6.1 with default settings on an Azure VM, with port 5601 open. This is a dev server with only one cluster. I am able to start Elasticsearch, Kibana and Logstash services and view them via a browser.
I have a some python code which is trying to connect to ElasticSearch using the recommended route of verifying https through the ca_certification route as per https://www.elastic.co/guide/en/elasticsearch/client/python-api/master/connecting.html
I have copied the http_ca.crt file from the VM onto my local machine and made it accessible.
es = Elasticsearch('https://localhost:9200',
ca_certs=CA_CERT,
basic_auth=(USER_ID,ELASTIC_PASSWORD))
Elasticsearch.yml has the following enabled
network.host: 0.0.0.0
http.host: 0.0.0.0
xpack.security.enabled: true
I appreciate that I can turn off security, but this isn't a sustainable approach moving forward.
The error I am getting is
elastic_transport.ConnectionError: Connection error caused by:
ConnectionError(Connection error caused by:
NewConnectionError(<urllib3.connection.HTTPSConnection object at
0x000001890CEF3730>: Failed to establish a new connection: [WinError
10061] No connection could be made because the target machine actively
refused it))
I suspect there is some configuration setting that I am missing somewhere.
Thanks in advance for any advise or pointers that can be offered.
The error message suggests that the Python code is unable to establish a connection to Elasticsearch on the specified host and port. There could be several reasons for this, including network configuration issues or problems with SSL/TLS certificates.
Here are some things you could try to troubleshoot the issue:
Check that Elasticsearch is running and listening on the correct host and port. You can use the curl command to test the connection:
curl -k https://localhost:9200
If Elasticsearch is running, you should see a JSON response with information about the cluster.
Check that the SSL/TLS certificate is valid and trusted by the Python client. You can use the openssl command to check the certificate:
openssl x509 -in http_ca.crt -text -noout
This will display detailed information about the certificate. Make sure that the Issuer and Subject fields match and that the Validity dates are correct.
Check that the firewall on the Azure VM is not blocking incoming traffic on port 9200. You can use the ufw command to check the firewall rules:
sudo ufw status
If port 9200 is not listed as "ALLOW", you can add a new rule:
sudo ufw allow 9200/tcp
Check that the Python client is using the correct ca_certs file. Make sure that the
CA_CERT
variable in your code points to the correct file location.
Check the Elasticsearch logs for any error messages that might indicate the cause of the connection problem. The logs are usually located in the logs directory of the Elasticsearch installation.
Hopefully, one of these steps will help you resolve the issue. Good luck!

How to download NLTK data?

I am new Data Science. Now I learn NLP. I need download nlkt data. I give this code:
nltk.download("punkt")
I get this error:
[nltk_data] Error loading punkt: <urlopen error [WinError 10061]
[nltk_data] Подключение не установлено, т.к. конечный компьютер
[nltk_data] отверг запрос на подключение>
I search internet but get any good information. What mean WinError 10061 error. Please help me. Thanks
WinError 10061 is a connection error that occurs when the system cannot establish a connection to a remote server or host. In the context of your code, it likely means that the NLTK library is unable to connect to the server hosting the "punkt" data package in order to download it. This can be caused by a few different things:
Network connectivity issues: There may be a problem with your internet connection, or the server hosting the data package may be down.
Firewall settings: Your firewall settings may be blocking the connection. You can try temporarily disabling your firewall to see if that resolves the issue.
Proxy settings: If you are behind a proxy server, your connection may be blocked by the proxy settings. You can try specifying the proxy settings in your code, or disabling the proxy temporarily.
Network permissions: You may not have the necessary permissions to access the server. Check your network settings and ensure that the appropriate permissions are set.
Try to check your internet connection and try again.
If the problem persists, you can try downloading the data package manually from the NLTK website and installing it locally on your machine. After that, you can specify the local path of the data package when using the nltk.download() function.
nltk.download("punkt", download_dir='path/to/local/data')
This will install the data package to your specified location, and the NLTK library will use that instead of trying to download it from the server.

Pip install commands error ConnectTimeoutError

I am trying to install Django 1.8.11 on my Windows 10 PC, but i am getting this error when run pip install django==1.8.11:
Retrying (Retry(total=0, connect=None, read=None, redirect=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000001CE97C60D68>, 'Connection to xxxx.xxxx.xxx.xx timed out. (connect timeout=15)')': /simple/pip/
(xxxx.xxxx.xxx.xx Is an address that I use as proxy some times)
I have Python version: 3.5.4
and pip version: 9.0.1
I have checked proxy settings with netsh winhttp show proxy
Current WinHTTP proxy settings:
Direct access (no proxy server).
I am not behind any corporate proxy
My system proxy settings are
Automatically detect settings -> ON
Use setup script -> OFF
Use a proxy server -> OFF
Also tried ping pypi.python.org
Ping statistics for 151.101.4.223:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 92ms, Maximum = 102ms, Average = 95ms
So, I have access to the internet
Also i removed temp files, tried python -m pip --proxy="" install django==1.8.11, searched the registry for data or value xxxx.xxxx.xxx.xx, same result...
If anyone knows where is that xxxx.xxxx.xxx.xx configured so I can remove it, don't know what else to do.
Look into the current environment variables, try to find any proxy setting:
set | find "proxy"
If anything found — unset the variables.
List settings from the config file:
pip config list | find "proxy"
If anything found — unset the variable using pip config unset or pip config edit. See the docs for pip config at https://pip.pypa.io/en/stable/reference/pip_config/
Try installing the latest version pip install Django
https://pypi.org/project/Django/

Accessing secure FTP server files

I am trying to connect to the omniture ftp host: ftp://ftp.omniture.com/ with a username and password. I am able to do this and access the files through the browser but connection through curl and wget times out:
curl ftp://myftpsite.com/a_file.zip --user myname:mypassword -o a_file.zip
Also trying to connect through the python library "ftplib" fails:
[Errno 110] Connection timed out
I want to programatically access files on this server. How can I do this?
I am trying not to install any other library. I do not have access and the process might delay things.

easy_install ReviewBoard [Errno 104] Connection reset by peer

I have a Kubuntu 10.04 VM image and am trying to install ReviewBoard by following The Linux Installation Wiki. When I get to the step to easy_install ReviewBoard, I encounter a problem I cannot find a solution to. Below is the console output:
>> sudo easy_install ReviewBoard
Searching for ReviewBoard
Best match: ReviewBoard 1.0.8
Processing ReviewBoard-1.0.8-py2.6.egg
ReviewBoard 1.0.8 is already the active version in easy-install.pth
Installing rb-site script to /usr/local/bin
Using /usr/local/lib/python2.6/dist-packages/ReviewBoard-1.0.8-py2.6.egg
Processing dependencies for ReviewBoard
Searching for pytz
Reading http://downloads.reviewboard.org/mirror/
Download error: [Errno 104] Connection reset by peer -- Some packages may not be found!
Reading http://downloads.reviewboard.org/releases/ReviewBoard/1.0/
Download error: [Errno 104] Connection reset by peer -- Some packages may not be found!
Reading http://pypi.python.org/simple/pytz/
Download error: [Errno 104] Connection reset by peer -- Some packages may not be found!
Reading http://pypi.python.org/simple/pytz/
Download error: [Errno 104] Connection reset by peer -- Some packages may not be found!
Couldn't find index page for 'pytz' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
Download error: [Errno 104] Connection reset by peer -- Some packages may not be found!
No local packages or download links found for pytz
error: Could not find suitable distribution for Requirement.parse('pytz')
I am new to python, but it seems like easy_install cannot decide on a version of pytz. I have read
104, 'Connection reset by peer' socket error, or When does closing a socket result in a RST rather than FIN?
http://homepage.mac.com/s_lott/iblog/architecture/C551260341/E20081031204203/index.html
and it seems like the problem described in those articles has more to do with development than my problem, but I could be wrong.
Has anyone encountered a problem like this? If there is any missing information that would help troubleshoot this, please let me know.
#Ben Hoffstein
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Link partner advertised link modes: Not reported
Link partner advertised pause frame use: No
Link partner advertised auto-negotiation: No
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: d
Wake-on: d
Current message level: 0x00000007 (7)
Link detected: yes
EDIT:
I'm not sure if this will be more useful information, but I tried installing the gitplugin for Trac and I received the same issue. So, it's looking like it may be a problem with easy_install.
>> sudo easy_install http://trac-hacks.org/svn/gitplugin/0.11
Downloading http://trac-hacks.org/svn/gitplugin/0.11
error: Download error for http://trac-hacks.org/svn/gitplugin/0.11: [Errno 104] Connection reset by peer
This is possibly a temporary problem with PyPI host, try again: easy_install pytz
like #Tarantula said, it is a temporary pypi service problem, i hit the same yesterday. i tried to ping pypi.python.org (or dig or host) a few times and find there are 2 servers returned by dns server. and it is because one of the pypi server keep throwing this error for one of the python package request.
so i hard coded the mapping pypi.python.org to the good one in /etc/hosts basically force pypi.python.org to resolve to the server i wanted and it relieved my pain. of course it is a temporary workaround when we have no control of the external service.
# add a line to /etc/hosts
151.101.200.223 pypi.python.org
get rid of the line when the service get back to normal.

Categories