Search code examples
pythoncharacter-encodingorientdb

Encoding for OrientDB (can't send a literal string)


I have the next problem. I need to create a vertex with a propertyA with a value 'المساء'. The problem is from python, python CAN'T send the string 'المساء' so...

I know I need to do a encode, like the next:

>>>a = 'المساء'
>>>b = a.encode('cp270')
>>>print b
>>>'\x9f\xe9\xea\xab\x9f\x98'

But with this encode OrientDB won't work. I think that I need an ascii encode.

There is the problem (without response): https://github.com/orientechnologies/orientdb/issues/5860

Anyone that know about OrientDB can help me? Thank in advance!


Solution

  • Using python I can do this:

    >>> a = 'غريبديالى#مخيسةالعز'
    >>> type(a)
    <type 'str'>
    >>> b = a.decode('utf8')
    >>> b
    u'\u063a\u0631\u064a\u0628\u062f\u064a\u0627\u0644\u0649#\u0645\u062e\u064a\u0633\u0629\u0627\u0644\u0639\u0632'
    >>> print b
    غريبديالى#مخيسةالعز
    

    So, if I put a query like the next will create a vertex with the next result:

    query = 'create vertex v content {"property":"%s"}' %b
    

    enter image description here