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.
Related
I have a script, which has been working fine in April 2021 when I created it, but now it gives me the following error. I'm not very experienced in coding, so if anyone can help me it would be great.
What I'm trying to do is simply download a song from youtube as a mp4. I can see that the error says there is something wrong with the pytube module imported, but I am not skilled enough to see what it is.
I'm using MacOS 12.1, Pycharm 2020.3, and Python 3.9.
Script:
import pytube
url = str('https://www.youtube.com/watch?v=gJLIiF15wjQ')
youtube = pytube.YouTube(url)
video = youtube.streams.get_by_itag(140)
video.download(output_path='/Users/clarajacobsen/Documents/TrueFIR/Klub100/Songs/', filename='test')
Error:
Traceback (most recent call last):
File "/Users/user/Documents/Folder1/venv/test.py", line 8, in <module>
video = youtube.streams.get_by_itag(140)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/__main__.py", line 292, in streams
return StreamQuery(self.fmt_streams)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/__main__.py", line 177, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/cipher.py", line 43, in __init__
self.throttling_plan = get_throttling_plan(js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/cipher.py", line 387, in get_throttling_plan
raw_code = get_throttling_function_code(js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/cipher.py", line 301, in get_throttling_function_code
code_lines_list = find_object_from_startpoint(js, match.span()[1]).split('\n')
AttributeError: 'NoneType' object has no attribute 'span'
After trying out solution 1, suggested by Sarim, error in PyCharm:
Traceback (most recent call last):
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/__main__.py", line 177, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/cipher.py", line 29, in __init__
self.transform_plan: List[str] = get_transform_plan(js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/cipher.py", line 197, in get_transform_plan
return regex_search(pattern, js, group=1).split(";")
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/helpers.py", line 129, in regex_search
raise RegexMatchError(caller="regex_search", pattern=pattern)
pytube.exceptions.RegexMatchError: regex_search: could not find match for iha=function\(\w\){[a-z=\.\(\"\)]*;(.*);(?:.+)}
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/Documents/Folder1/venv/test.py", line 5, in <module>
video = youtube.streams.get_by_itag(140)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/__main__.py", line 292, in streams
return StreamQuery(self.fmt_streams)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/__main__.py", line 184, in fmt_streams
extract.apply_signature(stream_manifest, self.vid_info, self.js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/extract.py", line 409, in apply_signature
cipher = Cipher(js=js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/cipher.py", line 29, in __init__
self.transform_plan: List[str] = get_transform_plan(js)
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/cipher.py", line 197, in get_transform_plan
return regex_search(pattern, js, group=1).split(";")
File "/Users/user/Documents/Folder1/venv/lib/python3.9/site-packages/pytube/helpers.py", line 129, in regex_search
raise RegexMatchError(caller="regex_search", pattern=pattern)
pytube.exceptions.RegexMatchError: regex_search: could not find match for iha=function\(\w\){[a-z=\.\(\"\)]*;(.*);(?:.+)}
After trying to run it in Google Colab:
/usr/local/lib/python3.7/dist-packages/pytube/cipher.py in get_throttling_function_code(js)
299
300 # Extract the code within curly braces for the function itself, and merge any split lines
--> 301 code_lines_list = find_object_from_startpoint(js, match.span()[1]).split('\n')
302 joined_lines = "".join(code_lines_list)
303
AttributeError: 'NoneType' object has no attribute 'span'
To fix this issue, This doesnt depends on which operating system you are on or which python you are using. Follow these steps:
I used Colab for this, if you are using Google colab use it and test it.
Install Pytube with !pip install pytube
After installing pytube just shutdown the kernel and the application you are using for it. either VSCode, Jupyter notebook or Colab. shut down its kernel.
Then run the enviroment again and try importing and running your code.
It should run now.
or if it gives you the same error as before:
Go to the files where pytube is install and go to folder in pytube named "pytube" then go into "cipher.py" and open it.
Search for the line: 293. Where name = re.escape(get_throttling_function_name(js))
Replace name = "iha"
Then close all kernels and file you are running the code on. and restart them completely after shutting down.
These two solutions should work 100%. Solution that worked for me is first one.
As the error tells us, you have a NoneType object called youtube in line 8 which was created before in line 7. Did you check if the YouTube link or anything on that video page that concerns you has changed?
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.
I'm new to Python.
I've to run this TargetFinder script ("Custom Analyses").
I installed all the required python packages, and copied the code into a script I named main.py, and ran it.
I got this error:
[davide#laptop]$ python main.py
Traceback (most recent call last):
File "main.py", line 8, in <module>
training_df = pd.read_hdf('./paper/targetfinder/K562/output-epw/training.h5', 'training').set_index(['enhancer_name', 'promoter_name'])
File "/usr/lib64/python2.7/site-packages/pandas/io/pytables.py", line 330, in read_hdf
return store.select(key, auto_close=auto_close, **kwargs)
File "/usr/lib64/python2.7/site-packages/pandas/io/pytables.py", line 680, in select
return it.get_result()
File "/usr/lib64/python2.7/site-packages/pandas/io/pytables.py", line 1364, in get_result
results = self.func(self.start, self.stop, where)
File "/usr/lib64/python2.7/site-packages/pandas/io/pytables.py", line 673, in func
columns=columns, **kwargs)
File "/usr/lib64/python2.7/site-packages/pandas/io/pytables.py", line 2786, in read
values = self.read_array('block%d_values' % i)
File "/usr/lib64/python2.7/site-packages/pandas/io/pytables.py", line 2327, in read_array
data = node[:]
File "/usr/lib64/python2.7/site-packages/tables/vlarray.py", line 677, in __getitem__
return self.read(start, stop, step)
File "/usr/lib64/python2.7/site-packages/tables/vlarray.py", line 817, in read
outlistarr = [atom.fromarray(arr) for arr in listarr]
File "/usr/lib64/python2.7/site-packages/tables/atom.py", line 1211, in fromarray
return cPickle.loads(array.tostring())
ValueError: unsupported pickle protocol: 4
I've no idea about what this pickle protocol means, and also my colleagues know nothing about it.
How can I solve this problem?
I'm using Python 2.7.5 on a CentOS Linux release 7.2.1511 (Core) operating system
The Pickle protocol is basically the file format. From the documentation,
The higher the protocol used, the more recent the version of Python needed to read the pickle produced. ... Pickle protocol version 4 was added in Python 3.4, your python version (2.7.5) does not support this.
Either upgrade to Python 3.4 or later (current is 3.5) or create the pickle using a lower protocol (2) in the third parameter to pickle.dump().
This sometimes happens due to incorrect data in the redis database. Try it:
sudo redis-cli flushall
It's a python version issue, upgrade it to the latest python version and try.
I'm getting the error:
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at
(http://www.w3.org/2001/XMLSchema.x sd), failed
when passing a Doctor (constructed with ImportDoctor) to the suds Client constructor.
I'm working on two Windows machines, both of them got the same version of suds installed, but only one of them rises the error above.
Could someone guide me here to know why this error rises?, so I can figure out what's missing on the machine where it happens?.
Thanks in advance!!!.
UPDATE: I don't really know if this is important, but it's worth noting that my Windows machine that is rising the error is an Amazon Web Services instance. At my local machine everything's working well!.
UPDATE: Here's some code I ran at the python interpreter of the machine I mentioned. Here you can detail how the error is rising...
>>> from suds.client import Client
>>> from suds.xsd.doctor import ImportDoctor, Import
>>> missing_import = Import("http://www.w3.org/2001/XMLSchema")
>>> missing_import.filter.add("http://tempuri.org/")
>>> doctor = ImportDoctor(missing_import)
>>> client = Client("http://etcfulfill.ebooks.com/Fulfillment.asmx?wsdl")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "suds\client.py", line 112, in __init__
self.wsdl = reader.open(url)
File "suds\reader.py", line 152, in open
d = self.fn(url, self.options)
File "suds\wsdl.py", line 159, in __init__
self.build_schema()
File "suds\wsdl.py", line 220, in build_schema
self.schema = container.load(self.options)
File "suds\xsd\schema.py", line 95, in load
child.dereference()
File "suds\xsd\schema.py", line 323, in dereference
midx, deps = x.dependencies()
File "suds\xsd\sxbasic.py", line 422, in dependencies
raise TypeNotFound(self.ref)
suds.TypeNotFound: Type not found: '(schema, http://www.w3.org/2001/XMLSchema, )'
>>> client = Client("http://etcfulfill.ebooks.com/Fulfillment.asmx?wsdl", doctor=doctor)
No handlers could be found for logger "suds.xsd.sxbasic"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "suds\client.py", line 112, in __init__
self.wsdl = reader.open(url)
File "suds\reader.py", line 152, in open
d = self.fn(url, self.options)
File "suds\wsdl.py", line 159, in __init__
self.build_schema()
File "suds\wsdl.py", line 220, in build_schema
self.schema = container.load(self.options)
File "suds\xsd\schema.py", line 93, in load
child.open_imports(options)
File "suds\xsd\schema.py", line 305, in open_imports
imported = imp.open(options)
File "suds\xsd\sxbasic.py", line 542, in open
result = self.download(options)
File "suds\xsd\sxbasic.py", line 567, in download
raise Exception(msg)
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at (http://www.w3.org/2001/XMLSchema.xsd), failed
UPDATE:
I realized that suds connections always open in TCP increasing ports, and if it reaches the maximum TCP port (65535) then it starts opening again from the minimum TCP port available, so there's no problem with this.
The problem shows up when using suds ImportDoctor, because it has to open a previous connection to the location where the import should be retrieved, and for some reason, if the system reaches the maximum TCP port count, then suds somehow assumes that there's no TCP port available to open the connection for obtaining the import, and in consecuence it throws the exception:
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at (http://www.w3.org/2001/XMLSchema.xsd), failed
I repeat, this only happens if suds has to open this previous connection for obtaining the import. If ImportDoctor is not used, then suds has no problem if the TCP port count reaches its maximum, it just restarts at the minimum port available.
Does anyone has any clue on how to resolve this issue???. I'd really appreciate the help!!!.
I've figured out what the problem was. The schema that was missing from the WSDL I was trying to use with suds was:
http://www.w3.org/2001/XMLSchema
And the XSD file for this schema is at:
http://www.w3.org/2001/XMLSchema.xsd
So when I used suds ImportDoctor to add this schema import, sometimes the w3.org domain was denying my access (don't know why really) and that's why this error was rising:
Exception: imported schema (http://www.w3.org/2001/XMLSchema) at (http://www.w3.org/2001/XMLSchema.xsd), failed
What did I do to solve this problem?. I just downloaded this schema to my machine and used suds ImportDoctor to retrieve this import locally.
And that was it!!!. Confusing bug!!!. But SOLVED.
I am getting ImportError: No localization support for language 'eng' when using MySQL Connector in Python.
My Traceback is as below.
Traceback (most recent call last):
File \"DB_Module.py\", line 151, in QueryDatabase
File \"\\share\app\Modules\mysql\connector\__init__.py\", line 44, in Connect
File \"\\share\app\Modules\mysql\connector\connection.py\", line 106, in __init__
File \"\\share\app\Modules\mysql\connector\connection.py\", line 325, in connect
File \"\\share\app\Modules\mysql\connector\connection.py\", line 288, in _open_connection
File \"\\share\app\Modules\mysql\connector\network.py\", line 326, in open_connection
File \"\\sfs\show_time\Showtime_Package\showtime\Modules\mysql\connector\errors.py\", line 160, in __init__
File \"\\share\app\Modules\mysql\connector\locales\__init__.py\", line 52, in get_client_error
ImportError: No localization support for language 'eng'
And my Current used SQL is
SELECT * FROM systemdetails
WHERE System_ID = 'System1' LIMIT 1
Can anyone tell me how to fix this error?
In order for the MySql connector to print the actual error string - it needs the eng/client_error file in the "locales" dir.
I personally, just manually created the dir "eng" and copy-paste the file from this link:
http://pydoc.net/Python/mysql-connector-python/1.0.7/mysql.connector.locales.eng.client_error/
> mkdir eng
> touch eng/__init__.py
> vi eng/client_error.py
> ... copy-paste, save, and exit.
I run the code again, and received:
2013: Lost connection to MySQL server during query
You'll probably get a different error, but hope it helps.
Just put this to import the locale when you compile again with pyInstaller or py2exe.
from mysql.connector.locales.eng import client_error
They will include the modules needed to fix the error.
In my case, changing the latest mysql.connector module to a former version solved the problem. I changed the version from 8.0.30 to 8.0.17.