Python - Socket Error, Address In Use - python

I'm currently attempting to setup a SiriServer (that's beside the point) on Xubuntu 12.10 x64, when I run the server python returns error
socket.error: [Errno 98] Address already in use.
The server by default is attempting to run on port 443, which unfortunetly is required in order for this application to work.
To double check if anything is running on port 443, I execute the following:
lsof -i :443
There's no results, unless I have something like Chrome or Firefox open, which I end up closing. Here's the full return from attempting to run the server application.
dustin#dustin-xubuntu:~/Applications/SiriServer$ sudo python siriServer.py
CRITICAL load_plugins Failed loading plugin due to missing module: 'Wordnik library not found. Please install wordnik library! e.g. sudo easy_install wordnik'
INFO <module> Starting Server
Traceback (most recent call last):
File "siriServer.py", line 493, in <module>
server = SiriServer('', options.port)
File "siriServer.py", line 425, in __init__
self.bind((host, port))
File "/usr/lib/python2.7/asyncore.py", line 342, in bind
return self.socket.bind(addr)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
I'm stuck on what to do, as this is the last part of setting up this application. Any help is appreciated.

You're not root -- that's your problem. To bind to ports under 1024 on Unix, you must be the superuser. So, hit su and try the python code again. Alternatively, bind to a port from 1024 to 65535.

This often happens when a python program doesn't exit properly when pressing ^C or ^Z. You could try reseting the terminal or exiting the terminal. You can also do killall -9 server.py
Another effective way to help prevent this even if you have root privs this can happen if a socket is not closed properly, here is a fix:
s=socket.socket( )
s.bind(("0.0.0.0", 8080))
while 1:
try:
c, addr = s.accept()
except KeyBoardInterrupt:
s.close()
exit(0)

I got that error even if port number is more than 1024
You can use
pkill -9 python
run command twice, it will list all python files which are killed

List all processes that you have running with
ps -a
Take the PID corresponding to python and pipe it into the kill command with (Example PID 2770)
kill -9 2770

Related

Odoo installation ''error: [Errno 98] Address already in use''

I followed this installation guide for odoo and I get an error in the very end
when I run odoo-bin file it gives me this error
teo#teo-Lenovo-Yoga-3-14:/opt/odoo/odoo-10.0$ ./odoo-bin
2017-07-06 15:03:20,583 3754 INFO ? odoo: Odoo version 10.0
2017-07-06 15:03:20,583 3754 INFO ? odoo: addons paths: ['/home/teo/.local/share/Odoo/addons/10.0', u'/opt/odoo/odoo-10.0/odoo/addons', u'/opt/odoo/odoo-10.0/addons']
2017-07-06 15:03:20,583 3754 INFO ? odoo: database: default#default:default
2017-07-06 15:03:20,601 3754 INFO ? odoo.service.server: HTTP service (werkzeug) running on 0.0.0.0:8069
Exception in thread odoo.service.httpd:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/opt/odoo/odoo-10.0/odoo/service/server.py", line 251, in http_thread
self.httpd = ThreadedWSGIServerReloadable(self.interface, self.port, app)
File "/opt/odoo/odoo-10.0/odoo/service/server.py", line 106, in __init__
handler=RequestHandler)
File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 440, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/usr/lib/python2.7/SocketServer.py", line 417, in __init__
self.server_bind()
File "/opt/odoo/odoo-10.0/odoo/service/server.py", line 116, in server_bind
super(ThreadedWSGIServerReloadable, self).server_bind()
File "/usr/lib/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/usr/lib/python2.7/SocketServer.py", line 431, in server_bind
self.socket.bind(self.server_address)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
error: [Errno 98] Address already in use
I think it may be related to the odoo.conf file because I specify a port but it still assumes de default port 8069
this is my odoo.conf file
[options]
; This is the password that allows database operations:
; admin_passwd = PASSWORD
db_host = False
db_port = 8470
db_user = odoo
db_password = False
addons_path = /opt/odoo/odoo-10.0/addons
;Log Settings
logfile = /var/log/odoo/odoo.log
log_level = error
Does anyone have an idea of what's happening, for the record I tried to install odoo before but failed so I already had DB user created for e.g.
Because odoo service automatically start when system starts, so you have to kill the odoo-service manually, and then run the ./odoo-bin file, at which point you should be able to see odoo running again.
sudo pkill -9 python
By doing this you'll stop python from finding the odoo service process id and subsequently killing that process.
ps aux | grep odoo
sudo kill <process id>
There are multiple pid running with odoo, ending with /etc/odoo-server.conf, which you have to select.
I think the best option is probably
sudo pkill -9 python
All the best, I hope I solved your problem.
Your odoo config has another DB port set, but 8069 is the port used for xmlrpc requests. If you want to change that in config, you have to set xmlrpc_port = 8470.
You getting this error because you have same port busy, you need to kill the existing process and then you can try again.
check process :
ps -aux|grep odoo.py
kill 09 [process id ]
You can check more details of installation tutorial here using Apache2 and WSGI : enter link description here
For this [Errno 98] error you use following two commands:
root#odoo:~# ps aux | grep odoo
Now you getting this type code
postgres 26041 0.1 2.3 1568276 196668 ? Sl Sep25 5:24 python ./odoo-bin
root#odoo:~# sudo kill -9 26041
Then your error will be fix.
[Errno 98] error you use following two commands
Get the id of the process running by following command
root#odoo:~# ps ax | grep servername
Then kill the already running process
sudo kill -9 process_id
You have another process running with the 8069 port. Kill the process killing python.
With the config file in odoo, you can change to different port changing 8069 with xmlrpc_port = 2003.
For example:
[options]
; This is the password that allows database operations:
admin_passwd = admin
db_host = 0.0.0.0
db_port = 5432
db_user = randall
db_password = admin
dbfilter = odoo
addons_path = /usr/lib/python2.7/dist-packages/openerp/addons
addons_path = /software/odoo/10.0/odoo-server/addons,/software/odoo/10.0/custom-addons,
xmlrpc_interface = 127.0.0.1
xmlrpc_port = 2002
Regards,
If your odoo set up, it's already running when you start your ubuntu.
It can be found in
/etc/init.d/odoo-server
Use this command to kill the existing services
ps -ef|grep odoo-bin
sudo kill ####
Solved with #ShivaGuntuku answer, just adding another way to solve the issue:
You're trying to run Odoo on port 8470, but as the error says you (Address already in use), another application is already running on that port (probably, another Odoo process).
So simply kill the process running on that port:
sudo fuser -k 8470/tcp
Then start your Odoo service again.

flask mod_wsgi address already in use [duplicate]

This question already has answers here:
How to kill a process running on particular port in Linux?
(34 answers)
Closed 6 years ago.
I have tried everything from last 2 days. But nothing really helped me out.
Background : I followed this to install flask app on production but I need to change serverName in vhost file so I forgot to kill an already running flask app/process and edited same vhost file to point to other location with few changes.
Problem : Now after apache restart, I continue getting following error when I access modified serverName.
mod_wsgi (pid=1685): Target WSGI script '/var/www/html/machine/machine.wsgi' cannot be loaded as Python module., referer: http://dev.badiyajobs.com/
mod_wsgi (pid=1685): Exception occurred processing WSGI script '/var/www/html/machine/machine.wsgi'., referer: http://dev.badiyajobs.com/
Traceback (most recent call last):
File "/var/www/html/machine/machine.wsgi", line$
from run import app as application
File "/var/www/html/machine/assessment/run.py",$
app.run()
File "/usr/local/lib/python2.7/dist-packages/fl$
run_simple(host, port, self, **options)
File "/usr/local/lib/python2.7/dist-packages/we$
inner()
File "/usr/local/lib/python2.7/dist-packages/we$
fd=fd)
File "/usr/local/lib/python2.7/dist-packages/we$
passthrough_errors, ssl_context, fd=fd)
File "/usr/local/lib/python2.7/dist-packages/we$
HTTPServer.__init__(self, (host, int(port)), $
File "/usr/lib/python2.7/SocketServer.py", line$
self.server_bind()
File "/usr/lib/python2.7/BaseHTTPServer.py", li$
SocketServer.TCPServer.server_bind(self)
File "/usr/lib/python2.7/SocketServer.py", line$
[self.socket.bind(self.server_address)
File "/usr/lib/python2.7/socket.py", line 224, $
return getattr(self._sock,name)(*args)
error: [Errno 98] Address already in use
Anybody please suggest how to get rid of already running app. I have tried lots of things regarding killing processes, but noting actually worked.
The easiest way to kill all processes that are listening on that port would be to use the fuser(1) command. For example, to see all of the processes listening for http requests on port 80 (run as root or use sudo):
fuser 80/tcp
If you want to kill them, then just add '-k' option
Source

Paramiko connection succeeds on linux but fails on windows

So, I have this program I made that connects to another computer (which is a linux machine) through SSH in python with the help of the library paramiko. I've made all the development on my ubuntu machine at work and it runs just fine on my home gentoo setup. I've been asked to make it work on a windows machine, and I get errors I cannot quite figure out what they mean to be honest, I'm not really confortable in windows environments.
The code is the following :
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect(
hostname=self.address,
username=self.username,
password=self.password
)
self.shell = self.ssh.invoke_shell(width=self.shell_width, height=self.shell_height)
self.transport = paramiko.Transport((self.address, self.port))
self.transport.connect(
username=self.username,
password=self.password
)
self.sftp = paramiko.SFTPClient.from_transport(self.transport)
So basically I have an interactive SSH shell I use to issue commands, and an SFTP connection as well to retrieve the files I created from the SSH session.
When running this code on windows :
Traceback (most recent call last):
File "C:/Users/labor/PycharmProjects/OPSS/OPSS.py", line 9, in <module>
shell.run("uptime")
File "C:\Python27\lib\site-packages\spur\ssh.py", line 162, in run
return self.spawn(*args, **kwargs).wait_for_result()
File "C:\Python27\lib\site-packages\spur\ssh.py", line 173, in spawn
channel = self._get_ssh_transport().open_session()
File "C:\Python27\lib\site-packages\spur\ssh.py", line 251, in _get_ssh_transport
raise self._connection_error(error)
spur.ssh.ConnectionError: Error creating SSH connection
Original error: [Errno 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
I don't really know what the system is trying to tell me when it says the party failed to respond because I can connect to it just fine with WinSCP and PuTTY from windows (which are the two programs I used to test both SSH and SFTP).
As you can tell I'm using PyCharm as my IDE, and I installed paramiko using its package manager on windows (on my linux machines I used pip).
Does anyone know what is happening ? And how can I make it work ? Thanks !

Socket connection refused after first message

I communicate Python with Matlab via sockets. However, even before going there, I want to test sockets with netcat. So I establish server using nc -lkp 25771, and make Python client to send a message to this server:
import socket
host = 'localhost'
port = 25771
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
s.send('Hello there')
s.close()
After running python client.py server prints out 'Hello there'; however, after I try to run client script one more time it raises exception.
Traceback (most recent call last):
File "client.py", line 13, in
s.connect((host,port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 111] Connection refused
Why the same command raises the error second time? What changes after my first command?
You are using traditional version of netcat (netcat-traditional) which doesn't support -k option. you can confirm checking the man page of your netcat by typing man nc in your terminal .
Install the netcat-openbsd version using the command
sudo apt-get install netcat-openbsd
now switch to netcat-openbsd version using the command
sudo update-alternatives --config nc
and choose the netcat-openbsd .
now you can use nc -lk 25771 .
this listens on port 25771 for multiple connections .
you can also use the commands discussed here
Netcat: using nc -l port_number instead of nc -l -p port_number

PyCharm remote debugging

I have remote Ubuntu server, and I'm trying set up remote debugging.
Configured as shown here.
import sys
import pydevd
sys.path.append('/root/home/scripts/pycharm-debug.egg')
pydevd.settrace('my_remote_server_IP', port=51234,
stdoutToServer=True, stderrToServer=True)
I also connect remote host for synchronizing and uploading my python scripts to remote server. (Tools -> Deployment -> ...)
When I start debugging:
C:\Python27\python.exe C:/Projects/python/demo.py
Could not connect to xx.xx.xx.166: 51234
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2.7.1\helpers\pydev\pydevd_comm.py", line 428, in StartClient
s.connect((host, port))
File "C:\Python27\Lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 10061] ����������� �� �����������,
Process finished with exit code 1
How to solve this problem?
The first argument of pydevd.settrace function should be the host, where PyCharm is installed. Not remote server.
Also in most cases if you want to run and debug your code remotely it is more convenient to use remote interpreter feature.
I resolved this problem by changing the port.

Categories