Repository: spesmilo/electrum

Issue:
problems with Electrum 1.9.5 on MacOSX
Electrum 1.9.5 behaves very strangely. I can start it, but electrum wants to connect to sn_0_28715873 on TCP port 1080. What is sn_0_28715873 and where's the domain name? Also, I'm using SSL w/o any proxies, so why does electrum want to connect to a socks port?
I can see my wallet, but electrum is not connected (although I allow all connections from electrum, even turned of the outbound fw for testing). When I try to open the network window, I get the following errors and the window does not open:

23.11.13 12:52:31 [0x0-0x1b61b60].org.pythonmac.unspecified.Electrum[53217] Traceback (most recent call last):
23.11.13 12:52:31 [0x0-0x1b61b60].org.pythonmac.unspecified.Electrum[53217] File "/Applications/Electrum.app/Contents/Resources/lib/python2.7/gui/qt/main_window.py", line 2137, in run_network_dialog
23.11.13 12:52:31 [0x0-0x1b61b60].org.pythonmac.unspecified.Electrum[53217] NetworkDialog(self.wallet.network, self.config, self).do_exec()
23.11.13 12:52:31 [0x0-0x1b61b60].org.pythonmac.unspecified.Electrum[53217] File "/Applications/Electrum.app/Contents/Resources/lib/python2.7/gui/qt/network_dialog.py", line 169, in init
23.11.13 12:52:31 [0x0-0x1b61b60].org.pythonmac.unspecified.Electrum[53217] self.proxy_mode.setCurrentIndex(self.proxy_mode.findText(str(proxy_config.get("mode").upper())))
23.11.13 12:52:31 [0x0-0x1b61b60].org.pythonmac.unspecified.Electrum[53217] AttributeError: 'str' object has no attribute 'get'

I'm using MacOSX 10.6.8 and Electrum 1.9.4 worked just fine.



Discussion:
I changed the link to 1.9.4 on the download page, until this is resolved

On OSX 10.8.5 running the Mac App from Terminal works smoothly but directly clicking the App keep it as disconnected. On OSX 10.9 works correctly.

I reported it to @maran to se if it is some .plist config problem.

if it's a plist config issue, logging out and logging back in again will reload the plist configurations.  When you just install the app from the dmg file, it doesn't necessarily reload the plist configs.

Not sure if this is the issue, but I got the issue with connecting the first time and now I am not getting the same issue anymore.  I wasn't able to get a traceback because it only happens when run from the app directly.

#455 and #448 are related (or duplicates) to this issue

I can reproduce this issue if I run from the command line like this:

> python electrum -p socks5:localhost:9150 -s electrumupzx5w5f.onion:8082:g -1 -v

If I just run:

> python electrum

I get no error on the network dialog.

Still looking into it....

Confirming still broken on stable 1.9.6 from DMG. Very strange behaviour. Double clicking the Electrum.app icon opens the app and does not connect. However, running `./Electrum.app/Contents/MacOS/Electrum` from Terminal does connect.

After running Electrum from terminal, opening via the icon does appear to work. But it won’t connect until you’ve run it from terminal at least once.

On Tuesday, December 17, 2013 at 9:40 AM, Lake Denman wrote:

> Confirming still broken on 1.9.6. Very strange behaviour. Double clicking the Electrum.app icon opens the app and does not connect. However, running ./Electrum.app/Contents/MacOS/Electrum from Terminal does connect.
> 
> —
> Reply to this email directly or view it on GitHub (https://github.com/spesmilo/electrum/issues/454#issuecomment-30772666).

@ldenman Same here. Running from the terminal as `/Applications/Electrum.app/Contents/MacOS/Electrum` works for me as well.
Unfortunately this does not really solve my problem, if I click on a bitcoin URL and Electrum is not running.

@adamipc Nope, even after I opened it manually via the terminal, Electrum will still not connect when I start it via double click.

@tessus Same here. I tried @adamipc's use case but could not reproduce. This is on OS X 10.8.5.

@tessus do you get any errors in the Console when you double click the icon?

I don't think it is OS version related. I'm on 10.6.8, but I also have a 10.9.0 on an external hard disk.

I have a feeling that some sort of a socksified stack made it somehow into the package, although this still wouldn't explain why it works from the terminal. This is truly a strange problem.

@wozz no, until I click on the network tab. Then I get the following output:

```
Dec 17 13:12:01 epsilon [0x0-0x14f94f8].org.pythonmac.unspecified.Electrum[26967]: Traceback (most recent call last):
Dec 17 13:12:01 epsilon [0x0-0x14f94f8].org.pythonmac.unspecified.Electrum[26967]:   File "/Users/tessus/Applications/Electrum.app/Contents/Resources/lib/python2.7/gui/qt/main_window.py", line 2167, in run_network_dialog
Dec 17 13:12:01 epsilon [0x0-0x14f94f8].org.pythonmac.unspecified.Electrum[26967]:     NetworkDialog(self.wallet.network, self.config, self).do_exec()
Dec 17 13:12:01 epsilon [0x0-0x14f94f8].org.pythonmac.unspecified.Electrum[26967]:   File "/Users/tessus/Applications/Electrum.app/Contents/Resources/lib/python2.7/gui/qt/network_dialog.py", line 169, in __init__
Dec 17 13:12:01 epsilon [0x0-0x14f94f8].org.pythonmac.unspecified.Electrum[26967]:     self.proxy_mode.setCurrentIndex(self.proxy_mode.findText(str(proxy_config.get("mode").upper())))
Dec 17 13:12:01 epsilon [0x0-0x14f94f8].org.pythonmac.unspecified.Electrum[26967]: AttributeError: 'str' object has no attribute 'get'
```

I tried to build it myself and after some issues (which @maran helped to solve) I was able to build it from the zip file. Building from git is failing with 'aes missing', although I have installed py-crypto.

Unfortunately I still have the same problem. I'm not a python developer, so I'm not much of a help debugging this issue.
Something happened after 1.9.4 which makes Electrum trying to connect to port 1080. The network window cannot be opened and Electrum will not connect. This only happens when Electrum is started via a double click.
Starting Electrum via the terminal works.

We need to figure out what the difference is between starting Electrum via double click and via terminal. This should help narrowing down this problem.

@tessus, I think the difference with aes is to install slowaes instead of py-crypto.  I believe you can do that with "pip install slowaes"

The main difference between Electrum starting from double click and via terminal is the Info.plist file (which sets up the environment when run from double click), so perhaps that's what we should focus on.  This is where it's created: https://github.com/spesmilo/electrum/blob/master/setup-release.py#L28

Maybe it needs another config setting in that file to make it work properly.

I wonder if this helps at all... I notice when I do this, it connects:

`open -a ~/Desktop/Electrum.app/Contents/MacOS/Electrum --args -1`

But this (which is the same as double clicking the icon) doesn't:

`open -a ~/Desktop/Electrum.app/Contents/MacOS/Electrum`

edit:

Actually, this works too:

`open -a ~/Desktop/Electrum.app/Contents/MacOS/Electrum --args -v`

It seems like any valid args that are passed makes it work.... weird.

@wozz there is no slowaes package on MacPorts, so I used `pip-2.7 install slowaes`, but got the following error:

```
Downloading/unpacking slowaes
  Could not find a version that satisfies the requirement slowaes (from versions: 0.1a1)
```

I looked at the Info.plist files for 1.9.4 and 1.9.6. There are almost no differences, whereas the most noticeable one is `argv_emulation`. I even changed the 1.9.6 Info.plist to use the exact same settings as on 1.9.4 (also tried to just use 1.9.4's Info.plist file).
None of these things worked.

I think @ldenman seems to be on the right track. I assume that the argument parsing got screwed up after adding the bitcoin URL code. 

@tessus, when you change the argv_emulation, it still doesn't work?  Also, when you change the plist file, you need to log out and log back in for OSX to properly load those settings.  Just restarting the program won't necessarily run with the new settings.

@wozz I didn't logout/login, because changing the Info.plist file usually works with ObjectiveC code w/o having to re-login - at least in my experiences.
But I can try that as well. I just have too many programs running at the moment to logout. I'll do that tomorrow. I'll also try to debug the arguments code then.

@tessus, yeah I didn't want to test it either because I have other things running :) ... although I'm not sure if it's even broken on mine.  I typically run it by using a QuickSilver shortcut though, so maybe it gets started differently. 

I'm restarting now to install some updates anyway, so I'll see if I can duplicate it and then hopefully fix it. 

Good luck. I'll give it a shot tomorrow.


Resolving patch:
diff --git a/setup-release.py b/setup-release.py
--- a/setup-release.py
+++ b/setup-release.py
@@ -35,7 +35,7 @@
     extra_options = dict(
         setup_requires=['py2app'],
         app=[mainscript],
-        options=dict(py2app=dict(argv_emulation=False,
+        options=dict(py2app=dict(argv_emulation=True,
                                  includes=['PyQt4.QtCore', 'PyQt4.QtGui', 'sip'],
                                  packages=['lib', 'gui', 'plugins'],
                                  iconfile='electrum.icns',
@@ -73,7 +73,11 @@
         qt_menu_location = "/opt/local/lib/Resources/qt_menu.nib"
     else:
         # No dice? Then let's try the brew version
-        qt_menu_location = os.popen("find /usr/local/Cellar -name qt_menu.nib | tail -n 1").read()
+        if os.path.exists("/usr/local/Cellar"):
+            qt_menu_location = os.popen("find /usr/local/Cellar -name qt_menu.nib | tail -n 1").read()
+        # no brew, check /opt/local
+        else:
+            qt_menu_location = os.popen("find /opt/local -name qt_menu.nib | tail -n 1").read()
         qt_menu_location = re.sub('\n', '', qt_menu_location)
 
     if (len(qt_menu_location) == 0):


Test patch: