Skip to content
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

Can't login: browser won't start up #2

Open
Pacman99 opened this issue Dec 16, 2020 · 15 comments
Open

Can't login: browser won't start up #2

Pacman99 opened this issue Dec 16, 2020 · 15 comments

Comments

@Pacman99
Copy link

I tried to login through the app and with setting the username as an environmental variable and I get this error:
OSError: [Errno 98] Address already in use

Here is the full python error trace:
log

I checked the spotify github issues and they said this error happens when another service is bound to port 8080, but I checked and theres nothing.
This is the output of sudo netstat -tulpn:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      3290/sshd: /usr/bin 
tcp6       0      0 :::22                   :::*                    LISTEN      3290/sshd: /usr/bin 
udp        0      0 0.0.0.0:67              0.0.0.0:*                           3700/dhcpd          
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           3987/chatty         
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           3987/chatty 

Thank you for writing this app! I can't wait to try it out once I'm able to login. I would appreciate any help with this problem.

@dann-merlin
Copy link
Owner

Hey, thanks for writing this issue!
This is puzzling me quite a bit. Which commit are you working with? When is this happening? I haven't updated the README yet, but the SPOTIPYNE_USERNAME environment variable isn't used anymore. I implemented a simple interface to login. You just have to input your username, click on submit and wait a second for your Browser to open.
As soon as you press the submit button, the app will try to open local server, if the app isn't authorized by spotify yet. This is where it breaks for you.
There can be two reasons for "Address already in use" AFAIK.

  1. Simple: There is already a program running (including the program itself), which is already listening on this port. This can be the case when you press the submit button too often. However this should not break anything. I will fix this in a later version.
  2. There was a program, which died ungracefully, that had listened on this port. In this case, you would have to wait for the kernel to clean this up. Alternatively one could reboot or just use the SO_REUSEADDR option for the socket. As far as I can tell this is actually done in the spotipy library.

So tl;dr:
Try using the login interface on the master branch and wait for the browser to open.

If this doesn't fix the problem, you can try to test if the SO_REUSEADDR flag is actually set, by temporarily adding a little print statement next to the corresponding line in the python library. This is should be in the function server_bind of class TCPServer in the file /usr/lib/python3.9/socketserver.py.
For me this is line 465.
Just add this line after it:
print("SET SO_REUSEADDR for TCPSocket")
(should be indented to be in the if self.allow_reuse_address block)
So next time you run the program, you should see the string printed. If you don't that's a problem and I will further investigate that.
Don't forget to remove that line again, as there might be lots of programs using this library.

@Pacman99
Copy link
Author

Pacman99 commented Jan 19, 2021

Thank you for responding! I'm really sorry about the delay. So I think the error was actually because the browser wasn't starting with the authorization page. And I thought it wasn't working and I hit the submit button again. The browser starts up when I hit the browser automation checkbox, but not otherwise. But I'm on a pinephone so I don't think the browser automation feature works. So I need to figure out how to get the browser to open without the automation method. I at least think thats the issue, I'll try and find more details.
EDIT: even when I check browser automation it starts firefox, but doesn't actually load the web page.

@Pacman99
Copy link
Author

I got it to work by installing on my laptop and copying the auth_token in the cache folder to my phone. Will there be any problem with this in the future?
Either way I don't think this is an issue with you're code, but prob something with phosh/pinephone or maybe the mobile-config firefox. My default browser is gnome-web but the app used firefox for some reason. I'll see if I can debug it more later for anyone else with the issue.
The app is really great when paired with spotifyd! Thanks for this :)
And one more question, is it possible to see your liked songs in the app?

@Pacman99
Copy link
Author

Pacman99 commented Jan 19, 2021

I also wrote a nix expression to install on my laptop, so if anyone else uses nix/nixos: https://gist.github.com/Pacman99/05dc55c8f5b51bab0b020b891022023a.

@dann-merlin
Copy link
Owner

Hey, great to hear it works now!
The Browser gets called from the spotipy library. It actually uses the webbrowser python-module to start a browser. This module respects the BROWSER-Environment Variable. So you can try to set it to the path of gnome-web or whatever browser you are using.

The behavior of firefox starting, but not loading the page, when using the automation feature on the pinephone is also what happens for me. I don't know why that is :(

Regarding your workaround: I think it should work, as long as your don't clear the cache (the token). I'm not entirely sure though. Maybe spotify will automatically log you out after a while. I don't know about that. And as this project is still very much work in progress, it might happen, that I'll reorder the cache structure or change the authentication, which might cause issues. Should be fine for now, though.

I would appreciate, if you could try setting the BROWSER environment variable and update me on if it works then!

Also, I wonder if I should link the nix expression in the README.md
I'm not using NixOS, but maybe someone else can find it there instead of it just hanging around in this issue. However I think it might make sense to also copy it to this repo and automatically update the it, whenever master is updated. Or is there a better way to got about this with nix expressions?

@Pacman99 Pacman99 changed the title Can't login with error: Address already in use Can't login: browser won't start up Jan 20, 2021
@Pacman99
Copy link
Author

Yeah look at that, I ran BROWSER=epiphany spotipyne and it sort of works. It brought me to login to spotify and after I did that it tried to redirect to the 127.0.0.1 url but started to hang. It did work but after a really long time and there was this error:

Exception occurred during processing of request from ('127.0.0.1', 45326)
Traceback (most recent call last):
  File "/usr/lib/python3.9/socketserver.py", line 316, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/usr/lib/python3.9/socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "/usr/lib/python3.9/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python3.9/socketserver.py", line 720, in __init__
    self.handle()
  File "/usr/lib/python3.9/http/server.py", line 427, in handle
    self.handle_one_request()
  File "/usr/lib/python3.9/http/server.py", line 415, in handle_one_request
    method()
  File "/home/alarm/.local/lib/python3.9/site-packages/spotipy/oauth2.py", line 1205, in do_GET
    self._write("""<html>
  File "/home/alarm/.local/lib/python3.9/site-packages/spotipy/oauth2.py", line 1220, in _write
    return self.wfile.write(text.encode("utf-8"))
  File "/usr/lib/python3.9/socketserver.py", line 799, in write
    self._sock.sendall(b)
BrokenPipeError: [Errno 32] Broken pipe
----------------------------------------

But it did get an auth_token and connected fine after that.

@Pacman99
Copy link
Author

Pacman99 commented Jan 20, 2021

For the nix expression, the best thing would be to merge it into nixpkgs and I can send the PR for the application whenever you're ready with the first release, I'm already a maintainer there.

I've found it to be a useful development tool too, and I've seen nix expressions like this either just as a default.nix in the root of projects or in a nix folder. The expression I made also has a patch to remove you're postinstall.py script from the meson.build because those tasks are already done with the wrapGApps hook and so the script conflicts. So I would recommend a nix folder since there are two files. If you want it, I can clean up my expression and submit a PR here. You can also just link the gist in the readme, I'll try to keep that updated.

@dann-merlin
Copy link
Owner

I tried reproducing this by installing epiphany on the pinephone myself, but had no luck.
It did hang for me for a while as well, but ultimately loaded the page and there was no error output.

The broken pipe error means, that apparently the browser closed the connection before the server was able to send the full html page (the server in this case is just a simple server the spotipy library starts). The browser probably closed the connection due to a timeout, as you reported that it was hanging for quite a while.

Question is: why was it hanging?
Can you try to reproduce this one more time? Just to check if the pinephone wasn't randomly hanging just because.

I think this might just come down to the pinephone's performance. So the browser might request the page, but the pinephone is too busy handling the browser, the app and just plain existance. So the server isn't able to send in time and it breaks.

Did spotipyne crash/did you have to restart to get logged in? Because in this case, I could try to at least fix that. Otherwise I don't know if there is much I can do.

@dann-merlin
Copy link
Owner

Also, I just realized I completely forgot to address your comments unrelated to the issue, so here it goes:

The app is really great when paired with spotifyd! Thanks for this :)

Glad you enjoy the app! I actually plan to add a button somewhere to start spotifyd from inside the app and add an option to autostart it with the app.

And one more question, is it possible to see your liked songs in the app?
Not right now, but I am working on this in the feature/rfct_library_overview branch
It isn't functional right now though.

@dann-merlin
Copy link
Owner

About the nix expression: I would happily merge a pull request. Adding it inside a folder sounds like a good idea!
A release will probably take a while though. I don't really have much time to work on spotipyne atm.

@Pacman99 Pacman99 reopened this Jan 21, 2021
@Pacman99
Copy link
Author

Pacman99 commented Jan 21, 2021

I tried reproducing this by installing epiphany on the pinephone myself, but had no luck.
It did hang for me for a while as well, but ultimately loaded the page and there was no error output.

Ohh Yeah I completely forgot to mention, I did try it a second time and it didn't work at all. Like even the socket error didn't come up. So even though thats an error, I think it does manage to get the auth token right before it errors out. But the second time I tried it, nothing happened epiphany just kept trying to load the redirect uri.

I think this might just come down to the pinephone's performance. So the browser might request the page, but the pinephone > is too busy handling the browser, the app and just plain existance. So the server isn't able to send in time and it breaks.

Yeah this could be it, but I think there might be more to it. The pinephone didn't feel slow at any point during this process. And I think spotipy uses flask internally, which is pretty minimal and doesn't usually have these problems. Have you gotten it to work with firefox, w/o the browser automation? Firefox should be even worse than epiphany in terms of resource usage.

@Pacman99
Copy link
Author

Glad you enjoy the app! I actually plan to add a button somewhere to start spotifyd from inside the app and add an option to autostart it with the app.

Not right now, but I am working on this in the feature/rfct_library_overview branch
It isn't functional right now though.

Oh wow both features would be really cool, I'm looking forward to it. If you create issues for features or tasks that need to be completed(or just say them) I might be able to help tackle some of them.

About the nix expression: I would happily merge a pull request. Adding it inside a folder sounds like a good idea!

Okay sounds good, I'll try and send something soon.

A release will probably take a while though. I don't really have much time to work on spotipyne atm.

Yeah of course, take your time!

@dann-merlin
Copy link
Owner

Have you gotten it to work with firefox, w/o the browser automation?

Yes, normal firefox works just fine. I'm not really sure what to do about this. I created a little branch, with a little check that should suppress the error output, when the pipe breaks. Doesn't solve the problem though.. :/

If you create issues for features or tasks that need to be completed(or just say them) I might be able to help tackle some of them.

That would be cool!
I used a cluttered TODO file before, but github issues are obviously much better. I just didn't even expect to see pretty much any interaction in this repository. Great to see I was wrong!
But be warned, I pretty much never programmed larger python projects before and never ever wrote a real gui program before. I hope it's not too bad though ^^

@Pacman99
Copy link
Author

Yes, normal firefox works just fine. I'm not really sure what to do about this. I created a little branch, with a little check that should suppress the error output, when the pipe breaks. Doesn't solve the problem though.. :/

Interesting, this is something I might need to debug more then. Firefox doesn't start up at all unless I hit the browser automation. But the browser automation doesn't even though it gets firefox to startup.

A general workaround could also be to display the url with some text saying, if the browser doesn't open for you go to this link. But that wouldn't help with the broken pipe error. I think the broken pipe error might be a separate issue altogether.

I used a cluttered TODO file before, but github issues are obviously much better. I just didn't even expect to see pretty much any interaction in this repository. Great to see I was wrong!

Yeah this project is really great, I was hoping for a native spotify app on my phone and I would definitely like to use it on my laptop at some point if it gets to be on par with the official spotify app.

But be warned, I pretty much never programmed larger python projects before and never ever wrote a real gui program before. I hope it's not too bad though ^^

Yeah I haven't done that much either, this is definitely new for me too. I'll go through the issues you posted and try and figure out what I could work on.

@dann-merlin
Copy link
Owner

A general workaround could also be to display the url with some text saying, if the browser doesn't open for you go to this link.

That sound like a good idea.

But that wouldn't help with the broken pipe error. I think the broken pipe error might be a separate issue altogether.

Yeah, I think a good start would be to catch the exception and just log a warning. #15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants