Pyserial: could not configure port: (5, 'Input/output error) - python

I've been trying to get the following two lines of Python code to run for the past two days, without much success:
import serial
ser = serial.Serial(0)
Each time I run it, I get the following error:
Traceback (most recent call last):
File "./test.py", line 4, in <module>
ser = serial.Serial(0)
File "/usr/lib/python2.7/dist-packages/serial/serialutil.py", line 260, in __init__
self.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 280, in open
self._reconfigurePort()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 308, in _reconfigurePort
raise SerialException("Could not configure port: %s" % msg)
serial.serialutil.SerialException: Could not configure port: (5, 'Input/output error')
I'm running Ubuntu 11.10 64-bit, with Pyserial 2.5 (python-serial 2.5-2.1) and Python 2.7 (python 2.7.2-7ubuntu2) and my user is a member of the dialout group.
I run Ubuntu 11.10 64-bit at work too, with the same versions of Python and Pyserial, and the problem doesn't seem to occur there. Any suggestions are welcome - I'm pretty flummoxed...
Thanks,
Donagh

This exception is thrown if the port is not available. On Linux, you can simply specify the exact name of the port to use, like
ser = serial.Serial('/dev/ttyACM0')

Related

PyDev breaking at built-in breakpoint

PyDev is breaking at the built-in breakpoint in Python code with the following error.
warning: Debugger speedups using cython not found. Run '"/Users/Work/opt/anaconda3/envs/ch_dev37/bin/python" "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/setup_cython.py" build_ext --inplace' to build.
Could not connect to 127.0.0.1: 5678
Traceback (most recent call last):
File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/_pydevd_bundle/pydevd_comm.py", line 462, in start_client
s.connect((host, port))
ConnectionRefusedError: [Errno 61] Connection refused
Traceback (most recent call last):
File "/Volumes/GoogleDrive/My Drive/free_energy_data/write_energies.py", line 111, in <module>
write_gases, write_adsorbates, verbose)
File "/Users/Work/opt/dev/gits/CatHub/cathub/catmap_interface.py", line 31, in write_energies
breakpoint()
File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/pydev_sitecustomize/sitecustomize.py", line 74, in custom_sitecustomize_breakpointhook
pydevd.settrace(*args, **kwargs)
File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/pydevd.py", line 2623, in settrace
notify_stdin=notify_stdin,
File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/pydevd.py", line 2688, in _locked_settrace
py_db.connect(host, port) # Note: connect can raise error.
File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/pydevd.py", line 1262, in connect
s = start_client(host, port)
File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/_pydevd_bundle/pydevd_comm.py", line 462, in start_client
s.connect((host, port))
ConnectionRefusedError: [Errno 61] Connection refused
I am running the Python code using the 'Run' option (Play button in the attached image) in GUI.
This behavior is surprising because as the release notes says breakpoint() builtin has been supported since earlier release (v6.5.0) of PyDev. So far I have used import pdb; pdb.set_trace() for a breakpoint and it is still functioning well. The breakpoint() builtin is working well without any problem outside PyDev in a terminal.
Additional Details:
Python Version: 3.7.8
Eclipse Version: 2020-09 (4.17.0)
PyDev Version: 8.0.1
Device: MacBook Pro
OS: macOS Big Sur 11.0.1
In this case, breakpoint() tries to connect to the IDE using the Remote Debugger, and, the ConnectionRefusedError: [Errno 61] Connection refused means that you haven't started the remote debugger in the client side.
So, to fix this, please start the debug server in the client side prior to the run (then on launch it will run without the debugger attached until breakpoint() is reached).
See: https://www.pydev.org/manual_adv_remote_debugger.html for info on how to start the remote debugger on the client side.

python and phoenixdb on Ubuntu (or Windows). How to?

I have created a python script connecting to a Phoenix HBase to analyze some data. I want to set this script up on crontab on a ubuntu server that I have running.
The script is perfectly able to run on my Windows 10 machine. But when I try to use the phoenixdb connector on Ubuntu I get an error on RunTime.
>>> import phoenixdb
>>> url = '<some-url>'
>>> conn = phoenixdb.connect(url, autocommit=True)
Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.5/site-packages/phoenixdb/avatica.py", line 156, in connect
self.connection.connect()
File "/usr/lib/python3.5/http/client.py", line 849, in connect
(self.host,self.port), self.timeout, self.source_address)
File "/usr/lib/python3.5/socket.py", line 711, in create_connection
raise err
File "/usr/lib/python3.5/socket.py", line 702, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/.local/lib/python3.5/site-packages/phoenixdb/__init__.py", line 63, in connect
client.connect()
File "/home/ubuntu/.local/lib/python3.5/site-packages/phoenixdb/avatica.py", line 158, in connect
raise errors.InterfaceError('Unable to connect to the specified service', e)
phoenixdb.errors.InterfaceError: ('Unable to connect to the specified service', TimeoutError(110, 'Connection timed out'), None, None)
I was hoping someone here knows a way to fix this problem?
I am running Python 3.6 on Windows and Python 3.5.2 on Ubuntu, but I doubt that that is the problem.
EDIT:
I have now started a Windows 2012 Server and have tried setting my script up here as well, and it seems not to be a problem solely for Ubuntu. I am getting the exact same error on Windows.
>>> import phoenixdb
>>> url = '<some-url>'
>>> conn = phoenixdb.connect(url, autocommit=True)
Traceback (most recent call last):
File "C:\Users\Administrator\Anaconda3\lib\site-packages\phoenixdb\avatica.py", line 156, in connect
self.connection.connect()
File "C:\Users\Administrator\Anaconda3\lib\http\client.py", line 936, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Users\Administrator\Anaconda3\lib\socket.py", line 722, in create_connection raise err
File "C:\Users\Administrator\Anaconda3\lib\socket.py", line 713, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Administrator\Anaconda3\lib\site-packages\phoenixdb\__init__.py", line 63, in connect
client.connect()
File "C:\Users\Administrator\Anaconda3\lib\site-packages\phoenixdb\avatica.py", line 158, in connect
raise errors.InterfaceError('Unable to connect to the specified service', e)
phoenixdb.errors.InterfaceError: ('Unable to connect to the specified service',
TimeoutError(10060, 'A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond', None, 10060, None), None, None)
I recently did format the PC that I developed the script on. The was using this phoenixdb connector, and I did not experience a similar problem on that.
I did also try to install Python 3.6 on the Windows machine (similar to the same python version that I installed on my normal PC - the one I developed the script on).
I'm really lost for finding a solution..
I finally found the problem. It had nothing to do with the machines I set up my script on. It had to do with security settings on the AWS Machines that both the Ubuntu and Windows Servers were.

getting 'ValueError: not open' when trying to open a connection with hidapi/hid on OSX

I am using python to open a hid/hidapi (the error is the same either way) connection on OSX El Capitan. However, It gives me the following error stacktrace:
Traceback (most recent call last):
File "/Users/johndoe/Library/Python/2.7/lib/python/site-packages/gevent/greenlet.py", line 534, in run
result = self._run(*self.args, **self.kwargs)
File "/Users/johndoe/IdeaProjects/projectname/emokit-master/python/emokit/emotiv.py", line 403, in setup
self.setup_darwin()
File "/Users/johndoe/IdeaProjects/projectname/emokit-master/python/emokit/emotiv.py", line 526, in setup_darwin
data = hidraw.read(34)
File "hid.pyx", line 105, in hid.device.read (hid.c:2338)
ValueError: not open
<Greenlet at 0x10f7f1b90: <bound method Emotiv.setup of <emokit.emotiv.Emotiv object at 0x10f532c50>>> failed with ValueError
I can't find anything on this, and do not usually use OSX or python, so I am at a bit of a loss
Often, hidapi needs sudo permissions on a mac for some reason. Even if you are running Ubuntu on a mac.

Reading arduino serial connection in python

I'm trying to connect to my Ardiuno with Python on my Ubuntu computer. I tried this example:
http://playground.arduino.cc/interfacing/python
But I always get:
>>> import serial
>>> ser = serial.Serial('/dev/tty.usbserial', 9600)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-x86_64/egg/serial/serialutil.py", line 282, in __init__
File "build/bdist.linux-x86_64/egg/serial/serialposix.py", line 289, in open
OSError: [Errno 2] No such file or directory: '/dev/tty.usbserial'
>>>
I can use the serial connection in sketch without any problems. I also added my user to the groups tty and dialout.
How do I connect to my Arduino using Python?
list the serial ports first. I'm not sure dev/tty.usbserial is correct.
You try do ls /dev/tty* in Terminal, pehaps your Arduino board will pop up as ttyACM0 or something like that(sorry, haven't used Ubuntu in a while).
You can also check out the PySerial finding ports article(may need PySerial 2.7 or newer)

Eclipse and PyDev debugger got errors but the program works well on win 7

I am doing debug in Eclipse (4.3.2v20140221-1852) with PyDev on Win 7.
My python is 3.2.5.
Eclipse Standard/SDK , Version: Kepler Service Release 2
PyDev is 3.5.0.201405201709 from Aptana.
I got error:
Unexpected error setting up the debugger
Socket operation on nonsocket: configureBlocking
This is different from
http://stackoverflow.com/questions/11388503/after-upgrading-eclipse-aptana-pydev-debugger-not-working
The errors are different from my errors:
pydev debugger: starting (pid: 16428)
Could not connect to IP_address: port_num
Traceback (most recent call last):
File "F:\my_path\eclipse432\eclipse\plugins\org.python.pydev_3.5.0.201405201709\pysrc\pydevd.py", line 1837, in <module>
debugger.connect(setup['client'], setup['port'])
File "F:\my_path\eclipse432\eclipse\plugins\org.python.pydev_3.5.0.201405201709\pysrc\pydevd.py", line 387, in connect
s = StartClient(host, port)
File "F:\my_path\eclipse432\eclipse\plugins\org.python.pydev_3.5.0.201405201709\pysrc\pydevd_comm.py", line 416, in StartClient
s = socket(AF_INET, SOCK_STREAM);
File "F:\my_path\python\python325\lib\socket.py", line 94, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
socket.error: [Errno 10022] An invalid argument was supplied
Any help would be appreciated.
I got that error when I switched computer and thought I could simply copy over the folder where I installed python as I did with my eclipse install. Downloading and re-installing using the python installer fixed the problem for me. Apparently, the installer overwrites the python dll in c:\windows\system32 and probably does other stuff.

Categories

Resources