Thanks for your expertise, everyone. We're running a python server using Cherrypy to expose/handle our API. This use to run fine before upgrading Ubuntu 10.10 to 11.04 (with inherent python updates), but, unfortunately, since then CherryPy does not bind to port 80 (using a proxy port 9998). The error dump is as follows:
2015-03-24 23:21:16,610 cherrypy.error - INFO - [24/Mar/2015:23:21:16] ENGINE PID 17194 written to '/var/tmp/MYSERVERNAME.pid'.
2015-03-24 23:21:16,611 cherrypy.error - INFO - [24/Mar/2015:23:21:16] ENGINE Started monitor thread '_TimeoutMonitor'.
2015-03-24 23:21:16,611 cherrypy.error - INFO - [24/Mar/2015:23:21:16] ENGINE Started monitor thread 'Autoreloader'.
2015-03-24 23:21:21,771 cherrypy.error - ERROR - [24/Mar/2015:23:21:21] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0x12ffa90>>
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/cherrypy/process/wspbus.py", line 147, in publish
output.append(listener(*args, **kwargs))
File "/usr/lib/pymodules/python2.7/cherrypy/_cpserver.py", line 90, in start
ServerAdapter.start(self)
File "/usr/lib/pymodules/python2.7/cherrypy/process/servers.py", line 60, in start
self.wait()
File "/usr/lib/pymodules/python2.7/cherrypy/process/servers.py", line 101, in wait
wait_for_occupied_port(host, port)
File "/usr/lib/pymodules/python2.7/cherrypy/process/servers.py", line 266, in wait_for_occupied_port
raise IOError("Port %r not bound on %r" % (port, host))
IOError: Port 9998 not bound on '127.0.0.1'
Running netstat to see what is occupying the port shows:
alpha$ sudo netstat -pnl | grep 8080
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 17194/python
As you can see, the python server with PID 17194 starts up, starts cherrypy (which fails). I'm not sure what's colliding with what here. As you can probably tell, I'm not a server guy but that doesn't stop me from mucking around and messing things up! Anyone have a clue why CherryPy might not be binding?
I uninstalled CherryPy and reinstalled CherryPy to the latest (3.2), and the problem resolved itself.
Related
I have a CherryPy script that I frequently run to start a server. Today I was having to start and stop it a few times to fix some bugs in a config file, and I guess the socket didn't close all the way because when I tried to start it up again I got this issue:
[23/Mar/2015:14:08:00] ENGINE Listening for SIGHUP.
[23/Mar/2015:14:08:00] ENGINE Listening for SIGTERM.
[23/Mar/2015:14:08:00] ENGINE Listening for SIGUSR1.
[23/Mar/2015:14:08:00] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.
[23/Mar/2015:14:08:00] ENGINE Started monitor thread 'Autoreloader'.
[23/Mar/2015:14:08:00] ENGINE Started monitor thread '_TimeoutMonitor'.
[23/Mar/2015:14:08:00] ENGINE Error in HTTP server: shutting down
Traceback (most recent call last):
File "/home/andrew/virtualenvs/mikernels/lib/python2.7/site-packages/cherrypy/process/servers.py", line 188, in _start_http_thread
self.httpserver.start()
File "/home/andrew/virtualenvs/mikernels/lib/python2.7/site-packages/cherrypy/wsgiserver/wsgiserver2.py", line 1848, in start
raise socket.error(msg)
error: No socket could be created
I edited CherryPy's wsgiserver2.py to see the details of the socket.error and error.strerror was
98 (98, 'Address already in use') Address already in use
Meanwhile my socket is constructed as:
af = 2
socktype = 1
proto = 6
canonname = ''
sa = ('0.0.0.0', 2112)
self.bind(af, socktype, proto)
(that's not exact code but that's what the values are when the error is fired)
I checked netstat and didn't see anything listening on port 2112, what could be causing the problem and how can I go about diagnosing it?
Thanks!
You can try the following
from socket import *
sock=socket()
sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
# then bind
From the docs:
The SO_REUSEADDR flag tells the kernel to reuse a local socket in TIME_WAIT state, without waiting for its natural timeout to expire.
Here's the complete explanation:
Running an example several times with too small delay between executions, could lead to this error:
socket.error: [Errno 98] Address already in use
This is because the previous execution has left the socket in a TIME_WAIT state, and can’t be immediately reused.
There is a socket flag to set, in order to prevent this, socket.SO_REUSEADDR:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
You could find the process and kill it by doing:
ps aux | grep python
, finding the process ID, and stopping it manually by doing:
sudo kill -9 PID
replacing PID with your PID.
I often have to do this while testing with Flask/CherryPy. Would be interested to see if there's an easier way (for e.g. to prevent it in the first place)
Much more easier to do it by:
Check the PID(:5000 is the host since I've been running on 127.0.0.1:5000):$ lsof -i :5000Then kill it:$ sudo kill -9 PID
I am using the following code with python3.8.2 connecting to Cisco network devices (switch, router), running in an eveNG lab environment. I am connecting from a mac laptop, to a router using telnet on IP 10.9.249.3 and port 32769.
Problem is that when I run this code I do not get any output. I can however see the commands being run and the running config output on the device itself using a separate connection. The code execution just stays put waiting for an event.
from telnetlib import Telnet
HOST = "10.9.249.3"
tn = Telnet(HOST,32769)
tn.write(b"terminal length 0\n")
tn.write(b"show runn\n")
tn.write(b"exit\n")
print(tn.read_all().decode('ascii'))
tn.exit()
When I do a control-break I get the following output:
^CTraceback (most recent call last):
File "p1.py", line 12, in <module>
print(tn.read_all().decode('ascii'))
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/telnetlib.py", line 335, in read_all
self.fill_rawq()
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/telnetlib.py", line 526, in fill_rawq
buf = self.sock.recv(50)
KeyboardInterrupt
I found similar issues posted and tried their suggestions like changing to a different Telnet read_*() method but no change in the output.
One thing I have noticed is that when I connect to the network device, I have to do the following to disconnect the (manual) telnet connection:
ctrl-]
telnet> quit
Connection closed.
Thanks and regards,
Abid Ghufran
I use mcpi: https://github.com/AdventuresInMinecraft/AdventuresInMinecraft-Linux
Starting the local server.
After, run program:
import mcpi.minecraft as minecraft
mc = minecraft.Minecraft.create()
mc.postToChat("Hello Minecraft World")
I am facing the below error:
Traceback (most recent call last):
File "/home/home/AdventuresInMinecraft/MyAdventures/HelloMinecraftWorld.py", line 2, in mc = minecraft.Minecraft.create()
File "/home/home/.local/lib/python3.6/site-packages/mcpi/minecraft.py", line 376, in create return Minecraft(Connection(address, port))
File "/home/home/.local/lib/python3.6/site-packages/mcpi/connection.py", line 17, in init self.socket.connect((address, port))
ConnectionRefusedError: [Errno 111] Connection refused
A ConnectionRefusedError means that the address + port combination was unable to be secured for this particular Minecraft server and thus raised an exception. This could be because some other application is already using the port of interest, the port is unavailable because of the OS, or a handful of other networking configuration mishaps.
But perhaps a better series of questions to ask yourself is:
What is the default address and port that minecraft.Minecraft.create() will attempt to launch / listen at?
Do I have access to that server (address + port)?
If I do have access, are there any security issues (AKA Firewall)?
This post has already addressed the root issue of your question, and I hope it gives you a good start at understanding the foundation of your problem.
Notice how their question mentions s.connect((host,port)) and your stack trace has self.socket.connect((address, port)) Looks like the same thing to me!
Some more reading:
- localhost
- check if port is in use
I encountered the same issue. I looked into the code of mcpi and found that the default port is 4711. However, a Minecraft Server's default port is 25565. All you need to do is add 2 parameters on the create() function. Code(Python):
mc = minecraft.Minecraft.create(address="127.0.0.1", port=25565)
btw change "address" in the code to the host of the server (only if you modified the "server.properties" file).
Also, ConnectionRefusedError doesn't mean that it's not secured, I believe it means that either the server is not online, it doesn't exist, or the server refused it for some reason.
EDIT:
Oops sorry I just found out that mcpi actually connects to the RaspberryJam plugin which is hosted on another IP and port. The plugin runs on port 4711. So mcpi has the right port.
So check if you have the RaspberryJam plugin installed. If not, download it from
https://www.spigotmc.org/resources/raspberryjuice.22724/
And put the .jar file inside the plugins folder in your server directory.
Trying to get the PYO music module to work on my Chromebook (Chroot Dev) (ARM7 processor) (Precise Penguin/ubuntu 12.04)
pyo:
>>>import pyo
pyo version 0.7.7 (uses single precision)
>>>pyo.Server(audio='jack').boot()
Due to the ARM processor and Precise some small modifications to the dependencies were necessary:
1] ARM changes to /proc/cpuinfo in relation to Jackd2, error:
FATAL: cannot locate cpu MHz in /proc/cpuinfo
solution? The error changed after, but not knowledgeable enough to know if for the better.
2] xwPython3.0 not available for Precise:
solution, shouldn't be a problem as this is UI dependency correct?
And to this is where the error is now:
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jackdmp 1.9.11
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2015 Grame.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
/usr/local/bin/jackd: symbol lookup error: /usr/local/bin/jackd: undefined symbol: jackctl_driver_params_parse
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
Jack error: Unable to create JACK client
jack_client_close called with a NULL client
Server not booted.
<pyolib.server.Server object at 0x1671150>
None of the solutions to any of the error messages i managed to find on google changed this error message. (google googled other, but you don't care about my messy internet history)
pulseaudio:
>pulseaudio --start
E: [pulseaudio] main.c: Daemon startup failed.
Could this be the main problem as Precise and the ChromeOS are running sidebyside and this causes a lock on the Deamon?
>pulseaudio --kill
E: [pulseaudio] main.c: Failed to kill daemon: No such process
>sudo pulseaudio --kill
E: [pulseaudio] core-util.c: Home directory /home/USERNAME not ours.
E: [pulseaudio] main.c: Failed to kill daemon: Permission denied
sudo permission denied??? PulseAudio running in ChromeOS???
jackd:
>jack_control start
Traceback (most recent call last):
File "/usr/local/bin/jack_control", line 399, in <module>
main()
File "/usr/local/bin/jack_control", line 158, in main
bus = dbus.SessionBus()
File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 211, in __new__
mainloop=mainloop)
File "/usr/lib/python2.7/dist-packages/dbus/_dbus.py", line 100, in __new__
bus = BusConnection.__new__(subclass, bus_type, mainloop=mainloop)
File "/usr/lib/python2.7/dist-packages/dbus/bus.py", line 122, in __new__
bus = cls._new_for_bus(address_or_type, mainloop=mainloop)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
This just doesn't work cause i "don't have a display" for Jackd to open up in right?
Solution 1: Connecting JACK to CRAS instead of ALSA, probably what you want unless you want to disconnect ChromeOS from audio (open link from solution 2 for more information)
Solution 2: Connecting ALSA and JACK directly to hardware by turning off CRAS
newcomer and first ever question here.
I am using the multiprocessing module of Python which is currently creating a Manager and a couple (45) processes on my localhost.
My Manager is set up as following:
manager = QueueManager(address=('', 50000), authkey='abracadabra')
manager.get_server().serve_forever()
I want also to create some other client processes remotely on another computer. So, let's say my IP is a.b.c.d, the Manager of the client in the remote computer is set up as following:
manager = QueueManager(address=('a.b.c.d', 50000), authkey='abracadabra')
manager.connect()
(yes, it's copy-pasted from the documentation).
However, I run the server and all 45 processes in localhost are fine, then I run the remote client and I get this:
Traceback (most recent call last):
File "govmap-parallel-crawler-client.py", line 144, in <module>
manager.connect()
File "/usr/lib/python2.6/multiprocessing/managers.py", line 474, in connect
conn = Client(self._address, authkey=self._authkey)
File "/usr/lib/python2.6/multiprocessing/connection.py", line 134, in Client
c = SocketClient(address)
File "/usr/lib/python2.6/multiprocessing/connection.py", line 252, in SocketClient
s.connect(address)
File "<string>", line 1, in connect
socket.error: [Errno 110] Connection timed out
Both computers can ping and ssh each other without problems.
My guess: there is one (or two!) firewall in between making the connection impossible. Is this correct?
If yes: is there a way to use a safe known port in order to avoid the firewall or maybe a more polite solution?
If no: what is happening?
Thanks!!
Use an ssh tunnel for interconnect? E.g on client:
ssh a.b.c.d -L12345:localhost:50000
If the client connects to localhost port 12345, it should be tunnelled to a.b.c.d port 50000.
EDIT: Of course, using an SSH tunnel might not be the best solution in a production environment, but at least it lets you eliminate other issues.
As defined by your snippet the server listens only on localhost (127.0.0.1) and not (a.b.c.d) thus you cannot connect from remote client.
To do so use:
manager = QueueManager(address=('a.b.c.d', 50000), authkey='abracadabra')
manager.get_server().serve_forever()