I'm using Docker-py and dockerpty in order to exec commands using the Docker Python API.
The code it's pretty simple:
container = client.inspect_container(containerId)[0]
dockerpty.exec_command(client, container, command)
When I want to execute commands such as echo 'hello' it works fine. However, commands like /bin/bash, even though I'm able to get the terminal, it is causing the following error:
ubuntu:test$ python main.py exec [containerid] /bin/bash
root#so1:/opt/apache# Traceback (most recent call last):
File "__main__.py", line 216, in <module>
main()
File "__main__.py", line 201, in main
ec.execute()
dockerpty.exec_command(client, container, command)
File "/usr/local/lib/python2.7/site-packages/dockerpty/__init__.py", line 44, in exec_command
PseudoTerminal(client, operation).start()
File "/usr/local/lib/python2.7/site-packages/dockerpty/pty.py", line 334, in start
self._hijack_tty(pumps)
File "/usr/local/lib/python2.7/site-packages/dockerpty/pty.py", line 373, in _hijack_tty
pump.flush()
File "/usr/local/lib/python2.7/site-packages/dockerpty/io.py", line 367, in flush
read = self.from_stream.read(n)
File "/usr/local/lib/python2.7/site-packages/dockerpty/io.py", line 120, in read
return self.fd.recv(n)
File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/contrib/pyopenssl.py", line 194, in recv
data = self.connection.recv(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1302, in recv
self._raise_ssl_error(self._ssl, result)
File "/usr/local/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1172, in _raise_ssl_error
_raise_current_error()
File "/usr/local/lib/python2.7/site-packages/OpenSSL/_util.py", line 48, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'ssl3_read_bytes', 'tlsv1 alert protocol version')]
When I create the client, I specify the tls_config to use tlsv1.2:
tls_config = docker.tls.TLSConfig(
client_cert=(cert, key),
ssl_version=ssl.PROTOCOL_TLSv1_2,
)
client = docker.Client(base_url=url, timeout=timeout,
tls=tls_config, user_agent=user_agent)
Why am I getting this 'tlsv1 alert protocol version' error, and how can I fix this?
In some older versions of Python, ssl.PROTOCOL_TLSv1_2 isn't available. You can easily check by attempting to import it from the Python console inside the container:
root#57c6d8b01861:/# python
Python 2.7.8 (default, Nov 26 2014, 22:28:51)
>>> import ssl
>>> ssl.PROTOCOL_TLSv1_2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'PROTOCOL_TLSv1_2'
>>> ssl.PROTOCOL_TLSv1
3
If this is the case, try updating Python in your docker image to >=2.7.9.
Also ensure that the openssl version is >=1.0.1.
Related
I have a micro:bit (v1.3 B) and am trying to use the Python bitio library on a MacBook (macOS Monterey). I've been following the getting started section and have gotten to the 'making a connection' section.
I've already 'flashed' the bitio.hex file to the micro:bit by uploading the file, and it successfully shows the bitio logo, like shown here.
When I run python3 counter.py it gives me the following error:
microbit.repl.repl.REPLException: Timeout trying to receive [
raw EPL; CTRL-B to exit
>]
The full traceback:
Traceback (most recent call last):
File "/Users/User/Downloads/bitio-master/src/counter.py", line 3, in <module>
import microbit
File "/Users/User/Downloads/bitio-master/src/microbit/__init__.py", line 130, in <module>
repl.to_raw()
File "/Users/User/Downloads/bitio-master/src/microbit/repl/repl.py", line 109, in to_raw
self.wait_repl_response()
File "/Users/User/Downloads/bitio-master/src/microbit/repl/repl.py", line 143, in wait_repl_response
self.receive("\r\nraw REPL; CTRL-B to exit\r\n>", timeout=2)
File "/Users/User/Downloads/bitio-master/src/microbit/repl/repl.py", line 82, in receive
raise REPLException("Timeout trying to receive [%s]" % buffer)
microbit.repl.repl.REPLException: Timeout trying to receive [
raw EPL; CTRL-B to exit
>]
The full output:
User#Users-Macbook-Pro src % python3 counter.py
No micro:bit has previously been detected
Scanning for serial ports
remove device, then press ENTER
scanning...
found 137 device(s)
plug in device, then press ENTER
scanning...
found 138 device(s)
found 1 new device
selected:/dev/tty.usbmodem14202
Do you want this device to be remembered? (Y/N)Y
connecting...
Traceback (most recent call last):
File "/Users/User/Downloads/bitio-master/src/counter.py", line 3, in <module>
import microbit
File "/Users/User/Downloads/bitio-master/src/microbit/__init__.py", line 130, in <module>
repl.to_raw()
File "/Users/User/Downloads/bitio-master/src/microbit/repl/repl.py", line 109, in to_raw
self.wait_repl_response()
File "/Users/User/Downloads/bitio-master/src/microbit/repl/repl.py", line 143, in wait_repl_response
self.receive("\r\nraw REPL; CTRL-B to exit\r\n>", timeout=2)
File "/Users/User/Downloads/bitio-master/src/microbit/repl/repl.py", line 82, in receive
raise REPLException("Timeout trying to receive [%s]" % buffer)
microbit.repl.repl.REPLException: Timeout trying to receive [
raw EPL; CTRL-B to exit
>]
Fixed the issue, turns out I had to give the terminal (or whatever editor/IDE used) full disk access in settings
I'm trying to connect a Tektronix TDS 1012B oscilloscope to my PC using Pyvisa.
I'm using Kubuntu 20.04, Python version 3.9.7 and Pyvisa version 1.11.3.
I do the following :
>>> import pyvisa
>>> rm = pyvisa.ResourceManager()
>>> rm.list_resources()
('USB0::1689::870::C021027::0::INSTR')
>>> scope = rm.open_resource('USB0::1689::870::C021027::0::INSTR')
>>> scope.query("*IDN?")
But I get this error message:
Traceback (most recent call last):
File "/home/pierre/anaconda3/lib/python3.9/site-packages/pyvisa_py/protocols/usbtmc.py", line 256, in write
return self.usb_send_ep.write(data)
File "/home/pierre/anaconda3/lib/python3.9/site-packages/usb/core.py", line 408, in write
return self.device.write(self, data, timeout)
File "/home/pierre/anaconda3/lib/python3.9/site-packages/usb/core.py", line 989, in write
return fn(
File "/home/pierre/anaconda3/lib/python3.9/site-packages/usb/backend/libusb1.py", line 837, in bulk_write
return self.__write(self.lib.libusb_bulk_transfer,
File "/home/pierre/anaconda3/lib/python3.9/site-packages/usb/backend/libusb1.py", line 938, in __write
_check(retval)
File "/home/pierre/anaconda3/lib/python3.9/site-packages/usb/backend/libusb1.py", line 602, in _check
raise USBTimeoutError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBTimeoutError: [Errno 110] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/pierre/anaconda3/lib/python3.9/site-packages/pyvisa/resources/messagebased.py", line 638, in query
self.write(message)
File "/home/pierre/anaconda3/lib/python3.9/site-packages/pyvisa/resources/messagebased.py", line 197, in write
count = self.write_raw(message.encode(enco))
File "/home/pierre/anaconda3/lib/python3.9/site-packages/pyvisa/resources/messagebased.py", line 157, in write_raw
return self.visalib.write(self.session, message)[0]
File "/home/pierre/anaconda3/lib/python3.9/site-packages/pyvisa_py/highlevel.py", line 543, in write
written, status_code = self.sessions[session].write(data)
File "/home/pierre/anaconda3/lib/python3.9/site-packages/pyvisa_py/usb.py", line 179, in write
count = self.interface.write(data)
File "/home/pierre/anaconda3/lib/python3.9/site-packages/pyvisa_py/protocols/usbtmc.py", line 436, in write
bytes_sent += raw_write(data)
File "/home/pierre/anaconda3/lib/python3.9/site-packages/pyvisa_py/protocols/usbtmc.py", line 258, in write
raise ValueError(str(e))
ValueError: [Errno 110] Operation timed out
When I use another type of oscilloscope this very simple code works fine. And when I use Pyvisa under Windows instead of Kubuntu, it also works.
Can someone help me fix this annoying issue?
Check out this link to a post from Tek in Tek's forums. They suggest using the pyvisa-py native Python VISA backend. This command instructs to use the pyvisa-py backend
rm = visa.ResourceManager('#py')
and you install by
pip install pyvisa-py
I don't have an Ubuntu machine at my fingertips so I don't know if there are packages available for installing from apt.
Connecting my TBS 1064 in SUSE has problems due to write permissions. This results in an time-out on requests like ask(). It is likely due to udev/rules, although I did not figure out what to put exactly to make it always work. For now one has to put the write permission (admin) for every USB reconnect, but then it is working.
Other devices do not have this problem and it is only a linux issue.
I have a simple Python script that runs Selenium, and I have tried using Torsocks (as usual) simply like this: torsocks python script.py. However, it failed with this error:
Traceback (most recent call last):
File "script.py", line 21, in <module>
browser = webdriver.Firefox(options=options)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 163, in __init__
log_path=service_log_path)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/service.py", line 47, in __init__
self, executable_path, port=port, log_file=log_file, env=env)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 42, in __init__
self.port = utils.free_port()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/utils.py", line 37, in free_port
free_socket.listen(5)
PermissionError: [Errno 1] Operation not permitted
Is it actually possible to use Torsocks like this?
I realize that I could send the request with SOCKS5 proxy, but I wonder if it could run using Torsocks, and if not, it would be great to get an explanation.
I am trying to lemmatize a Latin text using Python 3.5 in Pycharm 5.0.4 with the CLTK library, but there seems to be a problem with Git. I get the error git.exc.GitCommandNotFound: [WinError 2] The system cannot find the file specified among other errors I believe are related—see below for the full output. I have tried adding a Git repository to the project folder and adding the git.exe path to version control but that seems to have done nothing. What can I do to get Git to work properly—please keep in mind that I am a complete neophyte when it comes to Python in particular and not very experienced with programming in general.
Code:
from cltk.stem.lemma import LemmaReplacer
from cltk.stem.latin.j_v import JVReplacer
from cltk.corpus.utils.importer import CorpusImporter
corpus_importer = CorpusImporter('latin')
corpus_importer.import_corpus('latin_text_latin_library')
corpus_importer.import_corpus('latin_models_cltk')
#corpus_importer.import_corpus('phi5', '~/PHI5/')
#t.convert_corpus(corpus='phi5')
j = JVReplacer()
lemmatizer = LemmaReplacer('latin')
In = open("CIC.txt","rt")
Out = open("CIC4.txt","wt")
text = In.read()
text = text.lower()
text = j.replace(text)
Out.write(str(lemmatizer.lemmatize(text)))
In.close()
Out.close()
Output:
C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 5.0.4\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 58508 --file C:/Users/Rune/PycharmProjects/untitled/Pucker.py
pydev debugger: process 14648 is connecting
Connected to pydev debugger (build 143.1919)
--- Logging error ---
Traceback (most recent call last):
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\site-packages\git\cmd.py", line 604, in execute
**subprocess_kwargs
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1220, in _execute_child
startupinfo)
File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.4\helpers\pydev\pydev_monkey.py", line 387, in new_CreateProcess
return getattr(_subprocess, original_name)(appName, patch_arg_str_win(commandLine), *args)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\site-packages\cltk\corpus\utils\importer.py", line 134, in import_corpus
Repo.clone_from(git_uri, target_dir, depth=1)
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\site-packages\git\repo\base.py", line 885, in clone_from
return cls._clone(git, url, to_path, GitCmdObjectDB, progress, **kwargs)
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\site-packages\git\repo\base.py", line 826, in _clone
v=True, **add_progress(kwargs, git, progress))
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\site-packages\git\cmd.py", line 450, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\site-packages\git\cmd.py", line 878, in _call_process
return self.execute(make_call(), **_kwargs)
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\site-packages\git\cmd.py", line 607, in execute
raise GitCommandNotFound(str(err))
git.exc.GitCommandNotFound: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\logging\__init__.py", line 980, in emit
msg = self.format(record)
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\logging\__init__.py", line 830, in format
return fmt.format(record)
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\logging\__init__.py", line 567, in format
record.message = record.getMessage()
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\logging\__init__.py", line 330, in getMessage
msg = msg % self.args
TypeError: not enough arguments for format string
Call stack:
File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.4\helpers\pydev\pydevd.py", line 2411, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.4\helpers\pydev\pydevd.py", line 1802, in run
launch(file, globals, locals) # execute the script
File "C:\Program Files (x86)\JetBrains\PyCharm 5.0.4\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/Rune/PycharmProjects/untitled/Pucker.py", line 5, in <module>
corpus_importer.import_corpus('latin_text_latin_library')
File "C:\Users\Rune\AppData\Local\Programs\Python\Python35-32\lib\site-packages\cltk\corpus\utils\importer.py", line 136, in import_corpus
logger.error("Git clone of '%s' failed: '%s'", (git_uri, e))
Message: "Git clone of '%s' failed: '%s'"
Arguments: (('https://github.com/cltk/latin_text_latin_library.git', GitCommandNotFound('[WinError 2] The system cannot find the file specified',)),)
Process finished with exit code 0
You can manually download the corpus from https://github.com/cltk/latin_models_cltk and place it in the
~/cltk_data/latin/model/ folder (so ~/cltk_data/latin/model/latin_models_cltk/lemmata/ is an existing folder afterwards). Then you should be able to run the following just fine:
from cltk.stem.lemma import LemmaReplacer
LemmaReplacer('latin').lemmatize('some_latin_here')
For the same in Greek, just replace the 'latin' by 'greek' everywhere in these instructions. I imagine (but haven't tried) that it works the same for other languages too.
I am pretty sure that CLTK does not work with any Python version below 3.6, at least as of August 2017. I had a devil of a time getting 3.6 installed on Ubuntu (Ubuntu linus running dual boot from my PC laptop) but eventually got it to work. Also I specifically solved the problem that OP articulates above by following the instructions at https://disiectamembra.wordpress.com/2016/07/01/current-state-of-the-cltk-latin-lemmatizer/. Good luck!
I am trying to use gevent to write to kafka 0.7.2 using brod on python 2.7.
Here is the error message I get. Guess its due to blocking. brod supports tornado but I use gevent.
No handlers could be found for logger "brod.socket"
Traceback (most recent call last):
File "/var/chef/cache/src/gevent/gevent/greenlet.py", line 328, in run
result = self._run(*self.args, **self.kwargs)
File "worker_server.py", line 204, in execute_kafka_pipe
kafka.produce(topic,payload)
File "/usr/local/lib/python2.7/dist-packages/brod-0.3.2-py2.7.egg/brod/base.py", line 287, in produce
return self._write(request, callback)
File "/usr/local/lib/python2.7/dist-packages/brod-0.3.2-py2.7.egg/brod/blocking.py", line 98, in _write
return self._write(data, callback, retries)
File "/usr/local/lib/python2.7/dist-packages/brod-0.3.2-py2.7.egg/brod/blocking.py", line 89, in _write
wrote_length += self._socket.send(data)
File "/var/chef/cache/src/gevent/gevent/socket.py", line 441, in send
self._wait(self._write_event)
File "/var/chef/cache/src/gevent/gevent/socket.py", line 292, in _wait
assert watcher.callback is None, 'This socket is already used by another greenlet: %r' % (watcher.callback, )
AssertionError: This socket is already used by another greenlet: <bound method Waiter.switch of <gevent.hub.Waiter object at 0x1dece60>>
<Greenlet at 0x1d4b9b0: execute_kafka_pipe('topic-spend', '{"enode": 1, "city": "Cairns", "dl": "en", "wnode)> failed with AssertionError
I tried to use gevent-kakfa but depends on gevent-zookeeper.
When trying to connect to zookeeper i get this message:
Traceback (most recent call last):
File "/home/ubuntu/workspace/rtbhui-devops/servers/worker_server.py", line 68, in <module>
framework = gevent_zookeeper.ZookeeperFramework('localhost:2181', 10)
File "/usr/local/lib/python2.7/dist-packages/gevent_zookeeper/framework.py", line 241, in __init__
self.client = ZookeeperClient(hosts, timeout)
File "/usr/local/lib/python2.7/dist-packages/gevent_zookeeper/client.py", line 211, in __init__
self._event = gevent.core.event(
AttributeError: 'module' object has no attribute 'core'
Exception AttributeError: "'ZookeeperClient' object has no attribute '_event'" in <bound method ZookeeperClient.__del__ of <gevent_zookeeper.client.ZookeeperClient object at 0x274ded0>> ignored
Is there not a python lib that I can I write messages using gevent that works?
You might try https://github.com/hmahmood/kafka-python/tree/gevent-impl
which is currently submitted for PR to the mainline kafka-python library:
https://github.com/mumrah/kafka-python/pull/145
Try Pykafka
Although you should be able to configure kafka-python by passing in the selector used by gevent