[redland-dev] Using LibRDF with Python and PostgreSQL

Chris Spencer chrisspen at gmail.com
Sat Mar 12 17:17:34 CET 2011


I'm attempting to test librdf with Python and PostgreSQL, following
the Python example at
https://github.com/dajobe/redland-bindings/blob/master/python/example.py
and the PostgreSQL docs at
http://librdf.org/docs/api/redland-storage-module-postgresql.html

I created my test PG database with the script:

DB_NAME=librdf_test
DB_USER=librdf_test
DB_PASS=password
psql --user=postgres -c "DROP DATABASE IF EXISTS ${DB_NAME};"
psql --user=postgres -c "CREATE DATABASE ${DB_NAME};"
psql --user=postgres -c "DROP USER IF EXISTS ${DB_USER}; CREATE USER
${DB_USER} WITH PASSWORD '${DB_PASS}'; GRANT ALL PRIVILEGES ON
DATABASE ${DB_NAME} to ${DB_USER};"
createlang -U postgres plpgsql ${DB_NAME}

I then modified the Storage() call in example.py to use PG:

import RDF

storage=RDF.Storage(storage_name="postgresql",
                    name="librdf_test",

options_string="new='yes',host='localhost',database='librdf_test',user='librdf_test',password='password'")
if storage is None:
  raise Exception("new RDF.Storage failed")

model=RDF.Model(storage)
if model is None:
  raise Exception("new RDF.model failed")

statement=RDF.Statement(RDF.Uri("http://www.dajobe.org/"),
                        RDF.Uri("http://purl.org/dc/elements/1.1/creator"),
                        RDF.Node("Dave Beckett"))
if statement is None:
  raise Exception("new RDF.Statement failed")

model.add_statement(statement)

However, running this results in the error:

Traceback (most recent call last):
  File "example.py", line 43, in <module>
    model.add_statement(statement)
  File "/usr/lib/python2.6/dist-packages/RDF.py", line 734, in add_statement
    statement._statement)
RDF.RedlandError: 'postgresql insert into Statements failed with error
ERROR:  invalid byte sequence for encoding "UTF8": 0xf07326\nHINT:
This error can also happen if the byte sequence does not match the
encoding expected by the server, which is controlled by
"client_encoding".\n'

Googling this error found no helpful results. How do I resolve this?

Regards,
Chris


More information about the redland-dev mailing list