Python Docker SDK "Error while fetching server API version" - python

In the Python Docker SDK, When I do
import docker
docker.from_env()
I see
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
I have docker desktop running and this works in the terminal
$ docker run -it ubuntu
If I add a version number
docker.from_env(version="6.0.1")
it stops erroring, but it doesn't seem to matter what number I use. I also then see an error on
client.containers.run("ubuntu")
of
requests.exceptions.ConnectionError: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
I'm on Ubuntu 22.04 and I'm seeing the problem with both Poetry and plain pip + venv. I've looked through the dozen or so questions about that error message and tried everything that looked relevant.

My final solution was to uninstall Docker Desktop and install Docker Engine instead. I had to manually delete some Docker config files left over after installation too.

Related

running "docker search" in Heroku via python(flask)

I'm attempting to search docker hub for images using the command "docker search", via python code.
here is the piece of code for this action:
client = docker.from_env()
image_list = client.images.search('ubuntu')
running this in the command line works, and also running it via flask locally works.
however, when deploying to heroku, this crashes the site, and the logs say the following:
docker.errors.DockerException: Error while fetching server API version: ('Connection aborted.', FileNotFoundError(2, 'No such file or directory'))
which basically tells me docker isn't installed on the machine running docker.
I found this question:
Running Docker inside a Python app on Heroku?
but it wasn't answered and basically describes what I need.
any idea what I can do in this situation? thanks!

how to solve "An error occurred (InvalidClientTokenId)" AWS Chalice deployment error

I'm new to application development and decided to use AWS services for this project. however, I am having difficulty deploying chalice. every time I run "chalice deploy", I get an error.
here are the steps I followed along with commands for Windows:
upgraded my powershell
"virtualenv enve" : then ".\venv\Scripts\activate" # install and run virtual environment
"pip install aws cli" : # install aws command line interface
"aws configure" : # configure my AWS_KEY and AWS_SCERET
"pip install chalice" : # install chalice
"chalice new-project": # created a new project
"chalice deploy" # deploy
I get
An error occurred (InvalidClientTokenId) when calling the GetRole
operation: The security token included in the request is invalid.
I'm able to use localhost and run my application but not able to deploy to the server. I don't know what i'm doing wrong. someone, please help!
additional info:
my operating system is windows 10. I upgraded my PowerShell to 7
I somehow figured it out!. The error occurred because the command "
chalice deploy
" was used in the wrong directory. Make sure you are in the directory where your chalice file is before initializing it to deploy.

Python script on EC2 returns wrong signature type error

I'm coding a discord bot in python. Whenever I try to connect to a specific site, on my EC2 instance running Amazon Linux 2, the script returns the following error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientConnectorSSLError: Cannot connect to host secure.site.here:443 ssl:None [[SSL: WRONG_SIGNATURE_TYPE] wrong signature type (_ssl.c:1076)]
(actual url snipped.)
The bot itself is dockerized, running python:3.7.4-slim-buster. The error is not present when built with image python:3.7.4-slim-stretch.
I've also tested the same script built with base image -buster on MacOS and also a GCP Compute Engine instance, both are error free.
What am I missing? Any tips welcome.
First of all I checked the current tls version used by connection to the site. It was 1.2.
I got same error with wget so I understand that problem not in python itself, but somewhere in openssl and system settings.
On Ubuntu 20.04.1 LTS I upgrade openssl from 1.1.1f to 1.1.1g - it solves the issue for me. I followed this manual.

SSL Errors when uploading py file to proxy server via Twine

I have packaged up a python application using python setup.py sdist bdist_wheelon an Ubuntu machine.
I want to upload these files to a proxy server of Artifactory. I am using the following twine command to do it
twine upload --repository-url https://apro.example.net.au/api/pypi/example-python -u username -p password dist/* --client-cert /usr/lib/ssl/certs/my_cert.pem
When I run the command I am getting the following error
SSLError: HTTPSConnectionPool(host='apro.example.net.au', port=443): Max retries exceeded with url: /api/pypi/example-python (Caused by SSLError(SSLError(336265225, '[SSL] PEM lib (_ssl.c:2959)'),))
I have placed my my_certs.pem into /usr/lib/ssl/certs/ and ran update-ca-certificates to make sure the certificates are up to date.
When I was trying to figure out what the SSLError was I came across what line it was complaining in _ssl.c in cpython (https://github.com/python/cpython/blob/master/Modules/_ssl.c)
What does SSL_TLSEXT_ERR_OK exact mean? I cannot figure out what is wrong with the certificate as it works fine with other applications I run against it.
Turns out my proxy server of Artifactory was having issues with certificates

How to install Python packages over SSH Port Forwarding?

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.

Categories