Thursday, August 30, 2012

Sigurnost i državna uprava...

Upravo sam pročitao kako državna uprava razmišlja o uvođenju sustava koji bi omogućio građanima dobijanje informacija putem Interneta, a također i mogućnost da građani mijenjaju svoje podatke korištenjem istog sustava!

To je vrlo pohvalno, ali dio oko kojeg sam se naježio je kada sam pročitao da bi se koristilo korisničko ime i lozinka:
Ministarstvo znanosti, Hrvatski zavod za mirovinsko osiguranje, Zavod za zdravstveno osiguranje, Ministarstvo uprave i Porezna uprava u pilot-projektu će biti spojeni na jedan sustav kojem će svaki građanin moći pristupiti putem interneta koristeći korisničko ime i lozinku koju će dobiti od jedne od navedenih institucija. Identifikacijom u sustavu, građani će u početku moći koristiti po jednu od najjednostavnijih usluga od svake ustanove.
S obzirom koliko problema na Internetu ima, koliko je programska podrška nesavršena, koliko su ljudi nesavjesni i ležerni, i konačno, koliko je problema zbog korisničkog imena i lozinki to je jedan veliki veliki potencijalni problem koji bi omogućio krađu identiteta, a možda još i gore stvari!

U tom smislu smatram da bi tome trebalo jako jako oprezno pristupiti cijelom problemu. Sigurnost je nešto što ne donosi direktnu dobit i zbog toga su rijetki dovoljno svjesni potencijalnog problema da samoinicijativno uvode kontrole koje koštaju, a ne donose direktnu dobit. Pozitivan primjer je HNB i njegova pravila koja je nametnuo bankama kako bi se osiguralo Internet bankarstvo. Čak mislim da bi tu trebalo izglasati i odgovarajuće zakone, zakone koji bi obvezali sve na pažnju i odgovorno postupanje, a možda bi ti zakoni bili dovoljno inovativni da budu primjer svima u svijetu.

Uglavnom, vidjet ćemo kako će se to razvijati...

Wednesday, August 22, 2012

F17 and Python setuptools mixup...

For some time now I was having problems with Python's setuptools package. When I downloaded some package and tried to install it with the usual:
python setup.py install
I would receive the following error:
Traceback (most recent call last):
  File "setup.py", line 1, in
    from setuptools import setup, find_packages
  File "/usr/lib/python2.7/site-packages/setuptools/__init__.py", line 2, in
    from setuptools.extension import Extension, Library
  File "/usr/lib/python2.7/site-packages/setuptools/extension.py", line 5, in
    from setuptools.dist import _get_unpatched
  File "/usr/lib/python2.7/site-packages/setuptools/dist.py", line 6, in
    from setuptools.command.install import install
  File "/usr/lib/python2.7/site-packages/setuptools/command/__init__.py", line 8, in
    from setuptools.command import install_scripts
  File "/usr/lib/python2.7/site-packages/setuptools/command/install_scripts.py", line 3, in
    from pkg_resources import Distribution, PathMetadata, ensure_directory
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2755, in
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 704, in subscribe
    callback(dist)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2755, in
    add_activation_listener(lambda dist: dist.activate())
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2258, in activate
    map(declare_namespace, self._get_metadata('namespace_packages.txt'))
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 1847, in declare_namespace
    _handle_ns(packageName, path_item)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 1817, in _handle_ns
    loader.load_module(packageName); module.__path__ = path
  File "/usr/lib64/python2.7/pkgutil.py", line 246, in load_module
    mod = imp.load_module(fullname, self.file, self.filename, self.etc)
  File "/usr/lib/python2.7/site-packages/chameleon/__init__.py", line 1, in
    from .zpt.template import PageTemplate
  File "/usr/lib/python2.7/site-packages/chameleon/zpt/template.py", line 9, in
    from ..i18n import fast_translate
ImportError: cannot import name fast_translate
I already managed to solve this problem some time ago, but it reappeared and it was driving me nuts! And I forgot what I did! Googling didn't tell me a lot. So, I had to look into the code.

I had to search modules on disk, use print to see which one is actually loaded, and rpm/yum to query packages, but to cut the story short, in the end I found out that I had some dangling files and directories, probably because I did upgrade instead of clean install.The following ones were offending ones:
/usr/lib/python2.7/site-packages/chameleon/ast
/usr/lib/python2.7/site-packages/chameleon/core
/usr/lib/python2.7/site-packages/chameleon/genshi
/usr/lib/python2.7/site-packages/chameleon/i18n
This is easy to verify. Using 'rpm -qf <dir_or_file' shows for all of them (including files in those directories) that they are not owned by any package. So, I simply removed then and suddenly everything worked!

Tuesday, August 21, 2012

Fetching book data via ISBN...

Well, I needed a way to obtain book data based on its ISBN. Additional constraint was that it had to be in Python. Search quickly revealed that there are multiple Web services, one of which is ISBNdb. But there are others too. Look at this StackExchange question for some tips.

So, I decided to go with ISBNdb because I quickly stumbled on Python module for it. Additionally, I realized that Calibre uses this library, too. This turned out to be a mistake. I lost more than hour trying to make it work, just for a single search by ISBN. Googling for some example code didn't bring a lot. So, here is what I learned, maybe it helps someone out there.

First, let me say that there is a bug in the code in subversion. If you checked out version 41, then the bug is certainly there. You need to open file keys.py and change line 22 that reads like this:
_KEYS.append(k)
into:
 _KEYS[key] = k
Next, you also have to change line 62 in the same line that reads like this:
def __new__(cls, key, force_=False):
into this:
def __new__(cls, key, name, force_=False):

Also, to use this library, and ISBNdb in general, you have to register in order to get a key. Key is a string of 8 characters.

Now, we are ready to try the library. The easiest way is to position yourself into directory that contains isbndb/ directory from subversion (that way Python interpreter will be able to find the module, otherwise, you need to move it into some "system" place, or manipulate sys.path array.

The commands are:
>>> import isbndb
>>> isbndb.addKey('12345678')
Got from isbndb:
<?xml version="1.0" encoding="UTF-8"?>
<ISBNdb server_time="2012-08-21T14:16:45Z">
<KeyStats granted="9" access_key="12345678" requests="9" limit="0" /&gt:
<BookList total_results="0" page_size="10" page_number="1" shown_results="0"></BookList>
</ISBNdb>

True
>>> books=isbndb.IsbndbSearch(searchValue='0071378596')
>>> book=books[0]
>>> book.Title
'Mastering technical mathematics'
And that's enough to get you started. The rest you can find by youself using Python's introspection features and some code browsing.

In the end, I think that this library isn't mature enough, it also has debug statements embedded into it and the documentation is poor, at best!

About Me

scientist, consultant, security specialist, networking guy, system administrator, philosopher ;)

Blog Archive