Note that there are some explanatory texts on larger screens.

plurals
  1. POScript having trouble passing Unicode through a REST interface
    primarykey
    data
    text
    <p>I am having trouble getting my Python script to ass Unicode data over RESTful http call.</p> <p>I have a script that reads data from web site X using a REST interface and then pushes it into web site Y using it's REST interface. Both system are open source and are run on our servers. Site X uses PHP, Apache and PostgreSQL. Site Y is Java, Tomcat and PostgreSQL. The script doing the processing is currently in Python.</p> <p>In general, the script works very well. We do have a few international users, and when trying to process a user with unicode characters in their name things break down. The original version of the script read the JSON data into the Python. The data was converted automagically into Unicode. I am pretty sure everything was working fine up to this point. To output the data I used subprocess.Popen() to call curl. This works for regular ascii, but the unicode was getting mangled somewhere in transit. I didn't get an error anywhere, but when viewing the results on site B it is no longer correctly encoded. </p> <p>I know that Unicode is supported for these fields because I can craft a request using Firefox that correctly adds the data to site B.</p> <p>Next idea was to not use curl, but just do everything in Python. I experimented by passing a hand constructed Unicode string to Python's urllib to make the REST call, but I received an error from urllib.urlopen(): <code>UnicodeEncodeError: 'ascii' codec can't encode characters in position 103-105: ordinal not in range(128)</code></p> <p>Any ideas on how to make this work? I would rather not re-write too much, but if there is another scripting language that would be better suited I wouldn't mind hearing about that also.</p> <p>Here is my Python test script:</p> <pre>import urllib uni = u"abc_\u03a0\u03a3\u03a9" post = u"xdat%3Auser.login=unitest&" post += u"xdat%3Auser.primary_password=nauihe4r93nf83jshhd83&" post += u"xdat%3Auser.firstname=" + uni + "&" post += u"xdat%3Auser.lastname=" + uni ; url = u"http://localhost:8081/xnat/app/action/XDATRegisterUser" data = urllib.urlopen(url,post).read()</pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload