geier / pycarddav

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

Change default for 'verify' to a bool, not a str. #68

Closed asirinelli closed 11 years ago

asirinelli commented 11 years ago

In the AccountSection Class, the default for 'verify' option is set to 'True' which is a str type. It should be True which is a bool. If 'verify' is not set in the config file, the str 'True' will be used and pass to the requests module. The consequence will be an SSL error as the 'True' string will be used as certificate location.

geier commented 11 years ago

I get Traceback (most recent call last): File "/home/cg/.local/bin/pycardsyncer", line 7, in execfile(file) File "/home/cg/workspace/pycarddav/bin/pycardsyncer", line 42, in conf = conf_parser.parse() File "/home/cg/workspace/pycarddav/pycarddav/init.py", line 242, in parse conf = self._read_configuration(args) File "/home/cg/workspace/pycarddav/pycarddav/init.py", line 376, in _read_configuration values = parser.parse(section) File "/home/cg/workspace/pycarddav/pycarddav/init.py", line 122, in parse self.parsed[option] = filter(reader(self._parser, section, option)) File "/home/cg/workspace/pycarddav/pycarddav/init.py", line 138, in _parse_bool_string value = value.strip().lower() AttributeError: 'bool' object has no attribute 'strip'

While there seems to be an error with the location of the ssl cert, this doesn't seem to be it, the _parse_bool_string actually returns True or False (as a bool) if the string is True or Fale.

asirinelli commented 11 years ago

Here is the bug I have without my patch:

(carddav)antoine@speedy:~/tmp/carddav/pycarddav$ pycardsyncer --debug
DEBUG:root:Using configuration from /home/antoine/.config/pycard/pycard.conf
DEBUG:root:Ignoring default:debug in configuration file
CardDAV password (account Perso): 
DEBUG:root:Using configuration:
DEBUG:root: accounts:
DEBUG:root:     auth: basic
DEBUG:root:     name: Perso
DEBUG:root:     resource: https://XXX:443/XXX/
DEBUG:root:     user: XXX
DEBUG:root:     verify: True
DEBUG:root:     write_support: 
DEBUG:root: debug: True
DEBUG:root: filename: /home/antoine/.config/pycard/pycard.conf
DEBUG:root: sqlite:
DEBUG:root:     path: /home/antoine/.local/share/pycardabook.db
DEBUG:root: sync:
DEBUG:root:     accounts: set(['Perso'])
DEBUG:root:start syncing account Perso
Traceback (most recent call last):
  File "/home/antoine/tmp/carddav/bin/pycardsyncer", line 55, in <module>
    controllers.sync(conf)
  File "/home/antoine/tmp/carddav/local/lib/python2.7/site-packages/pycarddav/controllers.py", line 128, in sync
    auth=conf.account.auth)
  File "/home/antoine/tmp/carddav/local/lib/python2.7/site-packages/pycarddav/carddav.py", line 99, in __init__
    **self._settings)
  File "/home/antoine/tmp/carddav/local/lib/python2.7/site-packages/requests/sessions.py", line 335, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/antoine/tmp/carddav/local/lib/python2.7/site-packages/requests/sessions.py", line 438, in send
    r = adapter.send(request, **kwargs)
  File "/home/antoine/tmp/carddav/local/lib/python2.7/site-packages/requests/adapters.py", line 331, in send
    raise SSLError(e)
requests.exceptions.SSLError: [Errno 185090050] _ssl.c:340: error:0B084002:x509 certificate routines:X509_load_cert_crl_file:system lib
geier commented 11 years ago

as stated above, while there obviously is an error in the SSL verification, this should have nothing to do with the configuration. Please type these two lines into a python prompt:

import requests requests.get('https://XXX:443/XXX/') # and replace the XXX as above

this should raise the same exception as pycarddav does. If the errors disappears, it is probably pycarddav's fault, otherwise it's probably a problem with requests.

asirinelli commented 11 years ago

I believe, it is pycarddav fault:

In [3]: requests.get('https://www.monte-stello.com/')
Out[3]: <Response [200]>
geier commented 11 years ago

It looks like you are right, somewhere pycarddav messes up. But if you look at the Section._parse_bool_string() method, you'll see that it returns True (the Bool) on 'True' (the string) input. As stated above, you're commit breaks the config parser for me. I'll try to find some time on the weekend for this…

geier commented 11 years ago

this should be fixed in 964c337 (in the develop branch). Please reopen if the bug still occurs. Thx!