sensiblecodeio / scraperwiki-python

ScraperWiki Python library for scraping and saving data
https://scraperwiki.com
BSD 2-Clause "Simplified" License
159 stars 69 forks source link

cannot `import scraperwiki` on read only directory #53

Closed drj11 closed 10 years ago

drj11 commented 10 years ago

If I can't write to the current directory then import scraperwiki fails with a sqlite (!) error:

drj@services:~$ python -m 'scraperwiki'
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 151, in _run_module_as_main
    mod_name, loader, code, fname = _get_module_details(mod_name)
  File "/usr/lib/python2.7/runpy.py", line 109, in _get_module_details
    return _get_module_details(pkg_main_name)
  File "/usr/lib/python2.7/runpy.py", line 101, in _get_module_details
    loader = get_loader(mod_name)
  File "/usr/lib/python2.7/pkgutil.py", line 464, in get_loader
    return find_loader(fullname)
  File "/usr/lib/python2.7/pkgutil.py", line 474, in find_loader
    for importer in iter_importers(fullname):
  File "/usr/lib/python2.7/pkgutil.py", line 430, in iter_importers
    __import__(pkg)
  File "/usr/local/lib/python2.7/dist-packages/scraperwiki/__init__.py", line 10, in <module>
    import utils, sqlite
  File "/usr/local/lib/python2.7/dist-packages/scraperwiki/sqlite.py", line 11, in <module>
    _connect()
  File "/usr/local/lib/python2.7/dist-packages/scraperwiki/sqlite.py", line 9, in _connect
    dt = DumpTruck(dbname = dbname,  adapt_and_convert = False)
  File "/usr/local/lib/python2.7/dist-packages/dumptruck/dumptruck.py", line 95, in __init__
    self.connection=self.sqlite3.connect(dbname, detect_types = self.sqlite3.PARSE_DECLTYPES)
sqlite3.OperationalError: unable to open database file

This is horrible, and most unlibrary like.

It shouldn't try and open the sqlite file until it needs it.

We found this problem when deploying the newsreader website which being a good web server cannot write to its filesystem. It's loading data-services-helpers and it's not even using import scraperwiki, it just gets sucked in by data-services-helpers.

pwaller commented 10 years ago

:crying_cat_face:

drj11 commented 10 years ago

You can now import scraperwiki even if you can't write to the current directory (presumably as a result of the way .save() works with SQLAlchemy).

pwaller commented 10 years ago

No, it's that we defer opening the connection until first use, rather than doing it on module import, yay.