geier / pycarddav

DEPRECATED - use vdirsyncer & khard -- easy to use CLI CardDAV client
http://lostpackets.de/pycarddav
MIT License
98 stars 35 forks source link

.netrc needed? #34

Closed geier closed 11 years ago

geier commented 11 years ago

Traceback (most recent call last): File "/home/cg/.local/bin/pycardsyncer", line 5, in pkg_resources.run_script('pyCardDAV==0.4', 'pycardsyncer') File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 499, in run_script self.require(requires)[0].run_script(script_name, ns) File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1235, in run_script execfile(script_filename, namespace, namespace) File "/home/cg/.local/lib/python2.7/site-packages/pyCardDAV-0.4-py2.7.egg/EGG-INFO/scripts/pycardsyncer", line 76, in conf = SyncConfigurationParser().parse() File "/home/cg/.local/lib/python2.7/site-packages/pyCardDAV-0.4-py2.7.egg/pycarddav/init.py", line 262, in parse return conf if self.check(conf) else None File "/home/cg/.local/lib/python2.7/site-packages/pyCardDAV-0.4-py2.7.egg/EGG-INFO/scripts/pycardsyncer", line 53, in check auths = netrc().authenticators(hostname) File "/usr/lib/python2.7/netrc.py", line 31, in init with open(file) as fp: IOError: [Errno 2] No such file or directory: '/home/cg/.netrc'

geier commented 11 years ago

~> pycardsyncer Traceback (most recent call last): File "/usr/bin/pycardsyncer", line 76, in conf = SyncConfigurationParser().parse() File "/usr/lib/python2.7/site-packages/pycarddav/init.py", line 262, in parse return conf if self.check(conf) else None File "/usr/bin/pycardsyncer", line 53, in check auths = netrc().authenticators(hostname) File "/usr/lib/python2.7/netrc.py", line 31, in init with open(file) as fp: IOError: [Errno 2] No such file or directory: '/home/eye/.netrc'

dirk-olmes commented 11 years ago

I stumbled over this one, too. I'd blame the netrc module for blindly opening the file (see http://hg.python.org/cpython/file/2.7/Lib/netrc.py#l31).

A simple workaround:

diff --git a/bin/pycardsyncer b/bin/pycardsyncer
index 00ac3b4..963ada9 100755
--- a/bin/pycardsyncer
+++ b/bin/pycardsyncer
@@ -50,7 +50,11 @@ class SyncConfigurationParser(ConfigurationParser):

         if success and not conf.dav__passwd:
             hostname = urlsplit(conf.dav__resource).hostname
-            auths = netrc().authenticators(hostname)
+            auths = None
+            try:
+                auths = netrc().authenticators(hostname)
+            except IOError:
+                pass
             if auths:
                 if not conf.dav__user or auths[0] == conf.dav__user:
                     logging.debug("Read password for user %s on %s in .netrc",
geier commented 11 years ago

this is fixed in the develop branch, see commit cddddc62cd7cb112009ec14bc40d358bcf27b0dd I will probably release a 0.4.1 version containing this and some more fixes.