michael-lazar / rtv

Browse Reddit from your terminal
MIT License
4.65k stars 276 forks source link

Login fails on OS X #166

Closed valleybay closed 7 years ago

valleybay commented 9 years ago

I'm running rtv in iTerm 2 on OS X in zsh. I installed via pip. My python version is 2.7.10.

When attempting to log in I am redirected to the authorization page on reddit. The redirect is pointed to 127.0.0.1:65000. Is RTV running something there? It times out after a while.

professorjamesmoriarty commented 9 years ago

Check out https://github.com/michael-lazar/rtv#faq basicly you might need to use python3 not python2 for this.

kialam commented 8 years ago

This is still an issue. I installed rtv using pip3 and am still getting the same timeout and error as christiandalsvaag pointed out above.

michael-lazar commented 8 years ago

Hi thanks for pointing out that this is still a problem. If you could help provide me with some info, I would love to get to the bottom of this.

So what's supposed to happen is that we launch a python tornado webserver on your local port 65000. This server listens for a HTTP callback request from Reddit's OAuth. The request should be sent after you click the "allow" button and trigger a login through RTV. The two step process looks like this:

screenshot from 2015-11-28 19 53 13 screenshot from 2015-11-28 19 53 35

Just to clarify, are you saying that you click the "allow" button but the second page isn't loading on 127.0.0.0:65000? If so, could you try logging in, and when the page times out open a new terminal and type

$ netstat -anp | grep 65000  

and paste the results. I'm wondering if maybe you have another service running that is using that port.

kialam commented 8 years ago

Thanks Michael for the fast response.

Here are the results after running

netstat -anp tcp | grep 65000
tcp4       0      0  127.0.0.1.65000        127.0.0.1.56511        ESTABLISHED
tcp4       0      0  127.0.0.1.56511        127.0.0.1.65000        ESTABLISHED
tcp4     383      0  127.0.0.1.65000        127.0.0.1.56510        ESTABLISHED
tcp4       0      0  127.0.0.1.56510        127.0.0.1.65000        ESTABLISHED
tcp4     515      0  127.0.0.1.65000        127.0.0.1.56491        CLOSE_WAIT 
tcp4       0      0  127.0.0.1.56491        127.0.0.1.65000        FIN_WAIT_2 
tcp4       0      0  *.65000                *.*                    LISTEN     
tcp6       0      0  *.65000                *.*                    LISTEN     
michael-lazar commented 8 years ago

Thanks that looks good, 65000 is open and listening. I just checked and the whole thing would have crashed if the port was being used, so that's not the problem.

I wonder if this is an environment variable issue. Could you please try launching like this

$ DISPLAY=:1 rtv
kialam commented 8 years ago

That worked! My guess is that the DISPLAY variable is not set by default in OSX. I ran

echo $DISPLAY

in a terminal window and it returned nothing.

So, the variable itself needed to be set before running rtv?

michael-lazar commented 8 years ago

Cool I'm glad we figured it out! I'll have to look into this further, I'm not too familiar with how OSX works. On Ubuntu at least, we use $DISPLAY to check if you're able to open a new webbrowser window. If $DISPLAY isn't set, we fallback to trying to use a terminal-based browser. So the logic is getting screwed up where we think it's opening a terminal-based browser when it's actually not.

kialam commented 8 years ago

That makes sense. I noticed that the redirect to reddit page (that asks you to allow or deny rtv) looks different if I run

rtv

issue2

versus

DISPLAY=:1 rtv

issue1

michael-lazar commented 8 years ago

I pushed a fix to handle this here 2fa5adc7ce784ac65a6480a0b0d47a06f3eaedba. We now check if the operating system is OSX and set the DISPLAY to true if it is. I would still like to find a more robust solution to check for a display, but it should band-aid the problem for now.

veloxy commented 8 years ago

This still seems to be an issue for me with the latest master on OSX 10.11.6 - using DISPLAY=:1 rtv worked. Having the same issue as @kialam

michael-lazar commented 8 years ago

@veloxy what terminal are you using?

veloxy commented 8 years ago

@michael-lazar I'm using iTerm2, could that be the issue?

paoloap commented 8 years ago

Just to point out that I'm experiencing the same issue with Arch (default browser: vimb; terminal: termite, shell: zsh). Setting DISPLAY to :1 doesn't seem to work... Some more detail: usually my DISPLAY variable is set to :0. If I launch rtv I get an issue identical to OP. If I launch DISPLAY=:1 rtv and then I press u to login it lies there without even opening the browser. Using xterm instead of termite I get the same issue. Any tip? Thanks

UPDATE: First, I tried changing $BROWSER (BROWSER=firefox rtv) but it didn't work. Then, as a last try, I tested going full terminal (BROWSER=elinks rtv) and it finally authenticated me. So no problems anymore this side :)

ghost commented 7 years ago

I had this same problem with python3 and rtv 1.13.0 and Mac OS 10.12.1. Setting Display=:1 didn't work for me. I solved the problem by installing xquartz and logging into rtv from that terminal. Login persistence allowed me to revert to iterm2 or term.

michael-lazar commented 7 years ago

Thanks for the tip. I actually have a mac to test this on now, so I'll try to come up with a better solution.

michael-lazar commented 7 years ago

I re-applied the hack to force $DISPLAY to evaluate to true on OS X. I think this is the better option because the majority of users will be using RTV with a display and will want to use a standard web browser. The downside is that if you're on OS X and you want to use a terminal browser (w3m, links, etc), you will need to specify that explicitly by setting your $BROWSER variable.

jeromefaria commented 7 years ago

I just wanted to add that this still happens on a Mac running 10.12.2 but using DISPLAY=:1 rtv worked for me.

justthecontent commented 7 years ago

Happened on my mac 10.12.3.