Serial Communication Between Pycharm and Arduino - python

Traceback (most recent call last):
File "C:\Users\Dell\PycharmProjects\Arduino cv\Outputs\Led.py", line 11, in <module>
Arduino_Serial = serial.Serial('COM3', 9600) # Create Serial port object called arduinoSerialData
File "C:\Users\Dell\PycharmProjects\Arduino Cv\venv\lib\site-packages\serial\serialwin32.py", line 33, in __init__
super(Serial, self).__init__(*args, **kwargs)
File "C:\Users\Dell\PycharmProjects\Arduino Cv\venv\lib\site-packages\serial\serialutil.py", line 244, in __init__
self.open()
File "C:\Users\Dell\PycharmProjects\Arduino Cv\venv\lib\site-packages\serial\serialwin32.py", line 64, in open
raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM3': FileNotFoundError(2, 'The system cannot find the file specified.', None, 2)
I tried to create communication between pychram and arduino but my given com port cant open

Related

Tunneling not working using paramiko My machine > RDP to VM machine > network device via SSH

Can you please assist. I am doing some channeling from my windows machine via python. I could not get into the remote desktop. I am using ssh, but I know this seems to be wrong. This is working to jumpbox which is linux based.
My machine(windows) > remote desktop(VM machine) > network device via ssh
CODE:
for device in devices:
device = device.rstrip()
#for jump in jumphost_devices:
print("Connecting to Device %s..." % (device),)
jhost = paramiko.SSHClient()
jhost.set_missing_host_key_policy(paramiko.AutoAddPolicy())
jhost.connect('10.10.10.11', username=username, password=password, timeout=10)
vmtransport = jhost.get_transport()
dest_addr = (device, 22)
local_addr = ('10.10.10.11', 22)
vmchannel = vmtransport.open_channel("direct-tcpip", dest_addr, local_addr)
#
host = paramiko.SSHClient()
host.set_missing_host_key_policy(paramiko.AutoAddPolicy())
host.connect(device, username=username, password=password, sock=vmchannel, timeout=10)
remote_conn = host.invoke_shell()
#output = remote_conn.recv(1000)
ERROR:
C:\Users\xxxx\Documents\PYTHON>python push2.py device.txt command.txt logs
Enter Username: EV24049584
Password:
Retype your password:
Connecting to Device 10.120.120.138...
Exception: Error reading SSH protocol banner
Traceback (most recent call last):
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 2211, in _check_banner
buf = self.packetizer.readline(timeout)
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\packet.py", line 380, in readline
buf += self._read_timeout(timeout)
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\packet.py", line 622, in _read_timeout
raise socket.timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 2039, in run
self._check_banner()
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 2215, in _check_banner
raise SSHException(
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
Traceback (most recent call last):
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 2211, in _check_banner
buf = self.packetizer.readline(timeout)
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\packet.py", line 380, in readline
buf += self._read_timeout(timeout)
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\packet.py", line 622, in _read_timeout
raise socket.timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "push2.py", line 129, in <module>
main()
File "push2.py", line 125, in main
ssh_access_command(sys.argv[1], sys.argv[2], sys.argv[3])
File "push2.py", line 89, in ssh_access_command
jhost.connect('10.138.113.11', username=username, password=password, timeout=10)
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\client.py", line 406, in connect
t.start_client(timeout=timeout)
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 660, in start_client
raise e
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 2039, in run
self._check_banner()
File "C:\Users\xbsds\AppData\Local\Programs\Python\Python38-32\lib\site-packages\paramiko\transport.py", line 2215, in _check_banner
raise SSHException(
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
thanks,

SFTP connection failed socket.timeout?

I am attempting to connect to one of our SFTP servers in order to automate a report. We pull a file from this server once a week and I am not able to get this connections to work. I am not finding any useful references to the below traceback error. Anyone have an idea of what could be causing this problem?
I get a socket.timeout error after 2 or 3 seconds of executing the code.
import paramiko
cli = paramiko.SSHClient()
cli.set_missing_host_key_policy(paramiko.AutoAddPolicy())
cli.connect(hostname='AHOST', port=21, username="USER", password="PASS")
stdin_, stdout_, stderr_ = cli.exec_command("ls -l ~")
print(stdout_.readlines())
cli.close()
Traceback:
Exception: Error reading SSH protocol banner
Traceback (most recent call last):
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 2138, in _check_banner
buf = self.packetizer.readline(timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\packet.py", line 367, in readline
buf += self._read_timeout(timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\packet.py", line 576, in _read_timeout
raise socket.timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 1966, in run
self._check_banner()
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 2143, in _check_banner
"Error reading SSH protocol banner" + str(e)
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
Traceback (most recent call last):
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 2138, in _check_banner
buf = self.packetizer.readline(timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\packet.py", line 367, in readline
buf += self._read_timeout(timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\packet.py", line 576, in _read_timeout
raise socket.timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/user_name/PycharmProjects/PDD_Report/MAIN/MAIN.py", line 12, in <module>
cli.connect(hostname='A40T', port=21, username="user_name", password="gate001")
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\client.py", line 397, in connect
t.start_client(timeout=timeout)
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 587, in start_client
raise e
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 1966, in run
self._check_banner()
File "C:\Users\user_name\Desktop\Python 3.6.2\lib\site-packages\paramiko\transport.py", line 2143, in _check_banner
"Error reading SSH protocol banner" + str(e)
paramiko.ssh_exception.SSHException: Error reading SSH protocol banner
You are connecting to FTP port 21.
SSH/SFTP uses port 22 (what is the default value of the port parameter, which you override).
Side note 1: Your question is about SFTP. Yet, instead of using SFTPClient, you use SSHClient and execute shell commands – That has nothing to do with SFTP.
Side note 2: Do not use AutoAddPolicy like this. You
lose security by doing so.
See Paramiko "Unknown Server".

Neo4j Protocol Error: Server closed connection

I am new to neo4j world. I have successfully used it on my macbook. Now I am deploying it on a remote Linux machine with the same setup. But I keep getting this Protocol error. What caused this issue? How to fix this? I have been banging my head on this error for days.
Traceback (most recent call last):
File "/root/dev/knowledgeGraphH/knowledge/media_entity_mapper.py", line 31, in <module>
main()
File "/root/dev/knowledgeGraphH/knowledge/media_entity_mapper.py", line 28, in main
map_media_to_entities()
File "/root/dev/knowledgeGraphH/knowledge/media_entity_mapper.py", line 7, in map_media_to_entities
data_manager = DataManager()
File "/root/dev/knowledgeGraphH/knowledge/data_manager/data_manager.py", line 13, in __init__
self.graphDB = Neo4jManager()
File "/root/dev/knowledgeGraphH/knowledge/neo4j_manager.py", line 10, in __init__
self.session = self.driver.session()
File "/root/dev/knowledgeGraphH/env/lib/python2.7/site-packages/neo4j/v1/session.py", line 148, in session
session = Session(self)
File "/root/dev/knowledgeGraphH/env/lib/python2.7/site-packages/neo4j/v1/session.py", line 461, in __init__
self.connection = connect(driver.host, driver.port, driver.ssl_context, **driver.config)
File "/root/dev/knowledgeGraphH/env/lib/python2.7/site-packages/neo4j/v1/connection.py", line 465, in connect
return Connection(s, der_encoded_server_certificate=der_encoded_server_certificate, **config)
File "/root/dev/knowledgeGraphH/env/lib/python2.7/site-packages/neo4j/v1/connection.py", line 237, in __init__
self.fetch()
File "/root/dev/knowledgeGraphH/env/lib/python2.7/site-packages/neo4j/v1/connection.py", line 326, in fetch
self.acknowledge_failure()
File "/root/dev/knowledgeGraphH/env/lib/python2.7/site-packages/neo4j/v1/connection.py", line 273, in acknowledge_failure
fetch()
File "/root/dev/knowledgeGraphH/env/lib/python2.7/site-packages/neo4j/v1/connection.py", line 311, in fetch
raw.writelines(self.channel.chunk_reader())
File "/root/dev/knowledgeGraphH/env/lib/python2.7/site-packages/neo4j/v1/connection.py", line 169, in chunk_reader
chunk_header = self._recv(2)
File "/root/dev/knowledgeGraphH/env/lib/python2.7/site-packages/neo4j/v1/connection.py", line 152, in _recv
raise ProtocolError("Server closed connection")
neo4j.v1.exceptions.ProtocolError: Server closed connection
Seems to be port issue. Is the bolt port open or not? You have access to the port or not?
Check the output of the following command:
lsof -i tcp:7687
change the port number if you have changed bolt port address.
It turns out it was because I used the wrong credentials for this connection.

Python SSL FTP connection timing out

I'm trying to get a connection established to a FTP server with SSL from within Python (v3.3.0). But I keep getting a timeout. I am NOT using port 990 as the SSL port (paranoid). Would that be the cause of this problem? And if so, how do I specify the port I am using?
Here's my script:
from ftplib import FTP
from ftplib import FTP_TLS
ftps = FTP_TLS('ip address')
ftps.auth()
ftps.sendcmd('USER uname')
ftps.sendcmd('PASS password')
ftps.prot_p()
ftps.retrlines('LIST')
ftps.close()
And here is the result:
Traceback (most recent call last):
File "Scrpit name removed for posting", line 12, in <module>
ftps.retrlines('LIST')
File "C:\Python33\lib\ftplib.py", line 767, in retrlines
conn = self.transfercmd(cmd)
File "C:\Python33\lib\ftplib.py", line 381, in transfercmd
return self.ntransfercmd(cmd, rest)[0]
File "C:\Python33\lib\ftplib.py", line 742, in ntransfercmd
conn, size = FTP.ntransfercmd(self, cmd, rest)
File "C:\Python33\lib\ftplib.py", line 343, in ntransfercmd
source_address=self.source_address)
File "C:\Python33\lib\socket.py", line 424, in create_connection
raise err
File "C:\Python33\lib\socket.py", line 415, 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
any advice would be greatly appreciated,
After looking at the ftplib source, it doesn't seem to want to use any port but 21.
I think you should be able to work around this, something like
import ftplib
ftplib.FTP.port = 995 # or whatever port you are using
ftps = ftplib.FTP_TLS('hostname', 'user', 'pwd')
ftps.retrlines('LIST')
Set the port through the connect
import ftplib
ftps = ftplib.FTP_TLS()
ftps.connect ('hostname', 991)

Network is unreachable if running script on webhosting

The next script runs fine on my mac. When I try to run it on my WebHosting (bluehost) I'm getting socket.error: [Errno 101] Network is unreachable. Any idea how can I fix it?
#!/usr/bin/python
# Required header that tells the browser how to render the text.
print "Content-type: text/html\r\n\r\n";
import imaplib
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login('user#gmail.com', 'password')
mail.list()
# Out: list of "folders" aka labels in gmail.
mail.select("inbox") # connect to inbox.
print mail.list()
Traceback (most recent call last):
File "test2.py", line 6, in <module>
mail = imaplib.IMAP4_SSL('imap.gmail.com')
File "/home4/user/python27/lib/python2.7/imaplib.py", line 1148, in __init__
IMAP4.__init__(self, host, port)
File "/home4/user/python27/lib/python2.7/imaplib.py", line 163, in __init__
self.open(host, port)
File "/home4/user/python27/lib/python2.7/imaplib.py", line 1159, in open
self.sock = socket.create_connection((host, port))
File "/home4/user/python27/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 101] Network is unreachable
Their support isn't helpful at all.
Can it be port related or maybe SSL?
On bluehosts help pages they mention that outgoing connnections are restricted, so ther problem isn't with your program. The only way of getting outbound connections to be allowed seems to pay for it.

Categories

Resources