-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code loosing connection #171
Comments
Mpd is closing connections after a some timeout if your client is not doing anything. see #90 I cannot see the whole program so it is hard to tell what your pattern in the library is. |
I'm starting the code from etc/rc.local, so it starts immediately, and the error likewise, it seems. I have set the timeouts to none, So I wouldn't expect the connection to be closed that fast, but I might be wrong. The entire code is below: (The formatting is really annoying me, and I cant fix it, I have atatched the file as well, renamed .txt) |
Sorry this is not readable without proper indentation. If you could upload a repo or gist, I might have a look... |
Yes, terribly sorry about that. I uploaded a gist instead. It seems to be working. Please let me know if it doesn't. https://gist.github.com/Schmeling-M/3be163d0bf6fb3ac520df6dd9dc8ed54 One thing, that especially pussels me is that the raised exception in base.py, line 571 is raised because of this condition in line 569: if not line.endswith("\n"): Is this because the lack of "\n" means, that the connection to mpd is lost or.....? I should also mention, that the code is running on a Rpi4B with moode from moodeaudio.org. When the code is running, moode audio spits out the following error 3-5 times at startup: "MPD error JSON.parse: unexpected end of data at line 1 column 1 of the JSON data". I seems it could have a relation to the exception raised in base.py |
If read returns an empty string, this is detected as connection lost. I cannot see any obvious bug right now, but maybe check if the following code works for your: import logging, mpd
logging.basicConfig(level=logging.DEBUG)
client = mpd.MPDClient()
client.connect("localhost", 6600)
print(client.status()) |
I take it, your suggestion doesn't solve the problem. Only debugs it further, correct? |
Is mpd actually listening on this port? You can run tcpdump to see what is going on the wire:
And than run in another terminal, the same script. |
Also I would not run this code anywhere where untrusted clients have access to: |
Thankyou for all the suggestions and feedback. I'll test the connection in the following days, and see, if that might be the problem. Fortunately the player is on a private lan. No untrusted clients have access. |
It seems, I have a connection to mpd. At least I get the correct info, when running your python code: gives this So I'm guessing, the connection works initially, but with timeout set to none, I cant see why the connection i suddenly lost?? |
my mpd config /etc/mpd.conf looks like so: music_directory "/var/lib/mpd/music" decoder { input { resampler { audio_output { audio_output { audio_output { audio_output { audio_output { audio_output { audio_output { audio_output { root@moode:/etc# |
timeout is already None by default... you don't even need to set it. |
Perhaps, I should try to run you python code in a loop, like my code, and see if that will reproduce the error? |
I think I found the problem. If I run this code: https://gist.github.com/Schmeling-M/ae67c0b82f804dfcf65bc3f8a4d0081e It runs perfectly, until I connect to moode via bluetooth, in which case, it spits out exactly the same error as before DEBUG:mpd.base:Calling MPD status() So it seems that the error is natural, but why it occurs at startup, when I run the script from etc/rc.local I do not know.It could perhaps be because bluetooth forces an mpd disconnect, but I'm not sure. Do you have any idea, as to why this might be happening? |
not really no. |
I don't really see any actionable insights on what is broken here in the library. This seems more a setup issue. |
When I do this in my code:
if Client.status()['state'] == "play":
I get this:
Apr 14 08:34:14 moode systemd[1]: Stopped Music Player Daemon.
Apr 14 08:34:14 moode systemd[1]: Started Music Player Daemon.
Apr 14 08:34:14 moode rc.local[481]: Traceback (most recent call last):
Apr 14 08:34:14 moode rc.local[481]: File "/home/pi/ampcontroller.py", line 196, in
Apr 14 08:34:14 moode rc.local[481]: if Client.status()['state'] == "play": # Playing or Airplay active
Apr 14 08:34:14 moode rc.local[481]: File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 469, in mpd_command
Apr 14 08:34:14 moode rc.local[481]: return wrapper(self, name, args, callback)
Apr 14 08:34:14 moode rc.local[481]: File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 532, in _execute
Apr 14 08:34:14 moode rc.local[481]: return retval()
Apr 14 08:34:14 moode rc.local[481]: File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 454, in command_callback
Apr 14 08:34:14 moode rc.local[481]: res = function(self, self._read_lines())
Apr 14 08:34:14 moode rc.local[481]: File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 394, in _parse_object
Apr 14 08:34:14 moode rc.local[481]: objs = list(self._parse_objects(lines))
Apr 14 08:34:14 moode rc.local[481]: File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 240, in _parse_objects
Apr 14 08:34:14 moode rc.local[481]: for key, value in self._parse_pairs(lines):
Apr 14 08:34:14 moode rc.local[481]: File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 235, in _parse_pairs
Apr 14 08:34:14 moode rc.local[481]: for line in lines:
Apr 14 08:34:14 moode rc.local[481]: File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 586, in _read_lines
Apr 14 08:34:14 moode rc.local[481]: line = self._read_line()
Apr 14 08:34:14 moode rc.local[481]: File "/usr/local/lib/python3.7/dist-packages/mpd/base.py", line 571, in _read_line
Apr 14 08:34:14 moode rc.local[481]: raise ConnectionError("Connection lost while reading line")
Apr 14 08:34:14 moode rc.local[481]: mpd.base.ConnectionError: Connection lost while reading line
Apr 14 08:34:14 moode systemd[1]: rc-local.service: Control process exited, code=exited, status=1/FAILURE
Apr 14 08:34:14 moode systemd[1]: Created slice system-bluealsa\x2daplay.slice.
Apr 14 08:34:14 moode systemd[1]: Started BlueAlsa-Aplay.
Apr 14 08:34:14 moode systemd[1]: rc-local.service: Failed with result 'exit-code'.
Apr 14 08:34:14 moode systemd[1]: Failed to start /etc/rc.local Compatibility.
In the beginning of my code, I connect to mpd like so:
Client = mpd.MPDClient() # create client object
Client.timeout = None
Client.idletimeout = None
while True:
try:
Client.connect("localhost", 6600) # connect to localhost:6600
except:
continue
break
It seems like I get a connection error, but how do I solve this, and why am I loosing the connection???
The text was updated successfully, but these errors were encountered: