[redland-dev] unicode issue on os x with python bindings

Dave Beckett dave.beckett at bristol.ac.uk
Wed May 11 23:37:18 BST 2005


On Wed, 11 May 2005, Suzan Foster wrote:
> On May 11, 2005, at 10:31 PM, Christopher Schmidt wrote:
> 
> > On Wed, May 11, 2005 at 10:19:58PM +0200, Suzan Foster wrote:
> >> I'm hitting an error on my mac with a python script which I'm not
> >> seeing when running with windows. It's also my first attempt at 
> >> python,
> >> which doesn't help :-| Anybody who can steer me in the right 
> >> direction?
> >>
> >> http://www.ipodder.org/aboutTheDirectory threw an exception.
> >>   librdf_new_uri() argument 2 must be string without null bytes, not 
> >> str

which line?

> > Not sure exactly what "http://www.ipodder.org/aboutTheDirectory" is
> > supposed to be: if you could give a copy of the code snippet which is
> > causing the proglem, it might help me.

I can't run this script here, I get
Traceback (most recent call last):
  File "opmlwalker.py", line 4, in ?
    class OPMLWalker(saxutils.DefaultHandler):
AttributeError: 'module' object has no attribute 'DefaultHandler'


> Basically it's the RDF.Uri constructor that's failing. This is the 
> version with the use of str() as you suggested. This however throws the 
> same error. The full script was attached to my original post.
> 
>          def process_channel(self, uri):
>                  print "Found channel", uri
>                  try:
>                          statement = RDF.Statement(RDF.Uri(str(uri)), 
> self.rdftype, self.channel)
>                          if self.model.contains_statement(statement) : 
> return
>                          model = RDF.Model(self.storage)
>                          parser = RDF.Parser(name="rss-tag-soup")
>                          parser.parse_into_model(model, uri);
>                          if model.contains(statement):
>                                  self.model.add_statement(statement)
>                                  print "Added", uri
>                  except Exception, e:
>                          print uri, "threw an exception.", e
> 
> >
> > However, when I've run into this issue in the past, it has been as a
> > result of trying to pass in a <type 'unicode'> string rather than a
> > <type 'string'> string. You may want to check your code and run a str()
> > around anything that might be of type "unicode": you can test this by
> > using the function type(variable), and you can cast it by using
> > str(variable).
> 
> It was indeed of type unicode, however casting didn't solve the problem.

You shouldn't need to.  Although I'm not sure what the exact error line or 
data is, RDF.Uri has been able to handle unicode strings since redland 
bindings 1.0.0.2 since this code was added:
      elif type(arg) is unicode:
        import Redland_python
        args['string'] = Redland_python.unicode_to_bytes(arg)

it might be that there need to be other clauses in the RDF.Uri constructor 
to turn unicode strings into what redland expects.  This is to work around 
SWIG's inability to declare unicode strings.

Dave



More information about the redland-dev mailing list