docker api client/server version mismatch? - api

docker version showing correct api version for both client and server when i run inside python it is throwing error as below.
# docker version
Client:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-48.git0fdc778.el7.x86_64
Go version: go1.8.3
Git commit: 0fdc778/1.12.6
Built: Thu Jul 20 00:06:39 2017
OS/Arch: linux/amd64
Server:
Version: 1.12.6
API version: 1.24
Package version: docker-1.12.6-48.git0fdc778.el7.x86_64
Go version: go1.8.3
Git commit: 0fdc778/1.12.6
Built: Thu Jul 20 00:06:39 2017
OS/Arch: linux/amd64
#
But when i run with python it is throwing error as below.
# python
Python 2.7.5 (default, Aug 29 2016, 10:12:21)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import docker
>>> client = docker.APIClient(base_url='unix://var/run/docker.sock')
>>> print client.version()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/docker/api/daemon.py", line 177, in version
return self._result(self._get(url), json=True)
File "/usr/lib/python2.7/site-packages/docker/api/client.py", line 226, in _result
self._raise_for_status(response)
File "/usr/lib/python2.7/site-packages/docker/api/client.py", line 222, in _raise_for_status
raise create_api_error_from_http_exception(e)
File "/usr/lib/python2.7/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation)
docker.errors.APIError: 400 Client Error: Bad Request ("client is newer than server (client API version: 1.30, server API version: 1.24)")
>>>

It says API of your docker python package doesn’t match the docker engine server API. You should install a docker python package compatible with 1.24 or update your docker engine API to 1.30.
Additionally, you can try assigning new value to your docker client as follows:
client = docker.DockerClient(base_url='unix://var/run/docker.sock', version="1.24")
OR
client = docker.APIClient(base_url='unix://var/run/docker.sock', version="1.24")

Related

Netmiko - Windows 10 - SSH Router - Not able to run 1st command only

>>> from netmiko import ConnectHandler
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\netmiko\__init__.py", line 7, in <module>
Hello Experts,
Post applying from netmiko import ConnectHandler command I am getting above error.
Setup - Windows 10, Python 3.7, Netmiko installed. no other file present in pc with name netmiko.py.
Please suggest solution.
In order to use Netmiko, you need to be in the same python environment that you installed netmiko.
I see you installed Windows 10 and Python 3.7, but the python that is being used to call Netmiko is 2.7. You can tell from the "Python27" in the directory name C:\Python27\lib\site-packages\netmiko\__init__.py.
Run a Python 3.7 shell and try the command again. Make sure Netmiko is properly installed in the environment.
To verify if netmiko is installed, type help("modules") to retrieve a list of all installed packages. If Netmiko was properly installed, you should see it there.
Python 3.7.5 (tags/v3.7.5:5c02a39a0b, Oct 15 2019, 00:11:34) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help("modules")
Please wait a moment while I gather a list of all available modules...
---- output omitted ----
Cryptodome bdb gc pyexpat
__future__ binascii genericpath pygments
_string codecs netaddr tabnanny
_strptime codeop netapp tarfile
_struct collections netmiko telnetlib
_symtable colorama netmiko_globals tempfile
_testbuffer colorsys netrc terminal_server
_testcapi compileall nntplib test
_testconsole concurrent nt textfsm
_testimportmultiple configparser ntpath textwrap
_testmultiphase contextlib nturl2path this
_textfsm contextvars numbers threading
I hope this was helpful
Run : python3 to access python version 3.5+ terminal.
>>>from netmiko import ConnectHandler

Pycharm os.get_terminal_size() not working

Python 3.7.1 on Ubuntu 18.04.2 LTS
Using Pycharm version:
PyCharm 2019.1.3 (Professional Edition)
Build #PY-191.7479.30, built on May 30, 2019
Linux 4.18.0-22-generic
I'm having issues with the os.get_terminal_size() function call
Running the command from the terminal window works:
Python 3.7.1 (default, Oct 22 2018, 11:21:55)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.get_terminal_size()
os.terminal_size(columns=223, lines=18)
But running it from the Python Console window doesn't
>>>import os
>>>os.get_terminal_size()
Traceback (most recent call last):
File "<input>", line 1, in <module>
OSError: [Errno 25] Inappropriate ioctl for device
My googling hasn't produced much information specific to my issue at hand. What does OSError: [Errno 25] Inappropriate ioctl for device actually mean and how do I fix it?
Your implementation of Python relies on the terminal being compliant to the request for the terminal size by the OS. In the CPython implementation, the system call in ioctl() will fail because the device (terminal) doesn't recognize the command. You can try to set
-Drun.processes.with.pty=true
in Help/Edit Custom VM Options... as per this answer.
Instead of using os you can use shutil. This works without any hitch in Pycharm (and hopefully, by extension, IntelliJ).
import shutil
terminal_size = shutil.get_terminal_size(fallback=(120, 50))
# attributes
print('cols=', terminal_size.columns)
print('rows=', terminal_size.rows)

Certificate error when pulling docker images

When trying to pull a image from the docker hub, I am receiving some weird errors. The specific error that the docker daemon returns is:
Error getting v2 registry: Get https://registry-1.docker.io/v2/1:
x509: certificate signed by unknown authority
The weird thing is that running "docker search x" runs fine and returns what was expected. Also curling the page(curl -vL registry-1.docker.io) and running the openssl s_client(openssl s_client -connect registry-1.docker.io:443) doesn't return any certificate errors.
I am not behind a corporate proxy or anything like that. I've tried a lot of solutions like adding certs to the /etc/docker/certs.d directory, reinstalling the ca-certificates package, rebooting my machine, and almost everything that google searches suggested.
I am running CentOS version 6.8.
My docker version:
Client:
Version: 1.12.2
API version: 1.24
Go version: go1.6.3
Git commit: bb80604
Built: Tue Oct 11 17:00:50 2016
OS/Arch: linux/amd64
Server:
Version: 1.12.2
API version: 1.24
Go version: go1.6.3
Git commit: bb80604
Built: Tue Oct 11 17:00:50 2016
OS/Arch: linux/amd64
Thanks!

installing PySocks in Jython

I'm trying to develop software using Jython and SOCKS5, so I installed PySocks, but I'm receiving the following import error:
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_31
Type "help", "copyright", "credits" or "license" for more information.
>>> import socks
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "socks.py", line 117, in <module>
TypeError: Error when calling the metaclass bases
function() argument 1 must be code, not str
How can I correctly use PySocks in Jython?
“The Jython project strives to make all Python modules run on the JVM, but there are a few differences between the implementations. Perhaps the major difference between the two implementations is that Jython does not work with C extensions. Therefore, most of the Python modules will run without changes under Jython, but if they use C extensions then they will probably not work.”
According to the jython doc, it seems jython doesn't support C entensions.
you can install this lib by this cmd:
# sudo apt-get install python-socksipy
I found the response in :
How do I install Socks / SocksIPy on Ubuntu?

unable to figure out which package update lead to change of CA certs location for python requests package

I am trying to figure out which package update could have lead to change in the default CA location for python requests package. Listed below is my findings on 2 different nodes running RHEL 7.
One can check what cert-store is being used by requests package as specified below:
[root#compute-01 test]# python -mrequests.certs
/etc/pki/tls/certs/ca-bundle.crt
[root#compute-01 test]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root#compute-01 test]# python
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.7.0'
The same thing on the other node is as follows:-
[root#compute-25 test]# python -m requests.certs
/usr/lib/python2.7/site-packages/requests/cacert.pem
[root#compute-25 test]# openssl version
OpenSSL 1.0.1e-fips 11 Feb 2013
[root#compute-25 test]# python
Python 2.7.5 (default, Oct 11 2015, 17:47:16)
[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> requests.__version__
'2.7.0'
I am unable to figure out which package might have got upgraded which lead to this. I am unable to figure out what next I should check. Kindly advise.
One version of requests (the former) was installed by your system package manager and the latter was installed by pip.