Integers in TextNodes w/ Python minidom - soap

I am working on an API using SOAP and WSDL. The WSDL expects integers to come through. I am fairly new to ALL of this, and constructing XML in Python. I have chosen to use minidom to create my SOAP message. So using minidom, to get a value into a node I found I have to do this:
weight_node = xml_file.createElement("web:Weight")
weight_contents = xml_file.createTextNode(weight)
weight_node.appendChild(weight_contents)
So say weight needs to go in as an integer and IS an integer. The function is 'createTextNode' does this mean its going to be text, or what I put in there has to be text? Again I am fairly new to all of this. So if what I have explained seems way off base, please speak up.

Related

Dart - properly encode result from api

I am trying to solve the problem with chars encoding in api results. I have tried already to convince API provide to add utf-8 definition to header, but without success. So I need to convert result by myself in dart/flutter.
Tried already many things with Utf8Decoder or utf8.encode/decode, but without proper result.
Below example is in Polish. What I should have is:
Czesi walczą z pożarem
What I have in API results is:
Czesi walczÄ z pożarem
How can I decode the string to proper format?
Thanks!

Connect to a node with a String identifier

I'm trying to write a generic OPC-UA connector with Eclipse Milo.
Reading data from nodes already works fine when I'm using numeric nodeIDs, such as ns=0;i=2258. In milo I can simple construct the nodeID like this for example:
NodeId nodeIdentifier = new NodeId(Unsigned.ushort(nameSpaceID), uint(nodeID));
and it works fine.
But when I'm trying to connect to a note with a string identifier of a production node that only have a string identifier like shown in this image
the process fails with a StatusCode{name=Bad_NodeIdUnknown, value=0x80340000, quality=bad} exception.
I create the nodeIdentifier like this NodeId nodeIdentifier = NodeId.parse(nodeIDString);
and the parsed value looked like this:
ns=1;s=t|023_Messwert
First things first, you can’t just decide to use a string-based NodeId because you feel like it. If the server is exposing it as an integer-based NodeId then that’s what you have to use, as is the case with the CurrentTime Node being identified by ns=0;i=2258.
Parsing a string-based NodeId via NodeId.parse will work fine as long as it’s in the right format. What value are you trying to parse?

How to use Google Translate in Matlab?

I am writing a program to list all unique words in a movie subtitle file using Matlab. Now I have a unique word list that I want to translate to my language and learn the meaning before watching the movie.
Does anyone know how can I use Google Translate in Matlab so that I can complete my script? Is there any web service or so, and how can I use it in Matlab?
Thanks,
Appendix 1:
I have found this code useful:
%build url and send to google
url = 'http://ajax.googleapis.com/ajax/services/language/translate';
page = urlread(url, 'get', {'v', '1.0','q', inputString,'langpair', [sourceLanguage '|' destLanguage]});
but I don't know why it returns error each time I run it (e.g. 403 or 400). I know that my internet connection is okay when testing.
For a simple translator (I have no idea about quality), maybe try this. I didn't bother parsing the output:
langCodes = urlread('http://www.transltr.org/api/getlanguagesfortranslate'); % find your language code
textToTranslate = 'rabbit'; %change
langCodeOfOrigText ='en';
langCodeOfTranslation ='es';
translateURL = 'http://www.transltr.org/api/translate';
translateResults = urlread(translateURL, 'get', {'text',textToTranslate,'to',langCodeOfTranslation,'from',langCodeOfOrigText});
Just see next to translationText of the output for the result. Like I said, you can parse it, just google for a json to matlab struct parser.

Solr search error when dealing with Arabic string

I'm struggling with Solr search Arabic for several days and made some experiment. Here is the simple reflection of the problem.
After I store some Arabic sentence (now only 1 word السوري ) into database and have Solr index it, then query it by q=*:*&wt=python,(if no wt part, it was garbled chars) the response is:
'\u00d8\u00a7\u00d9\u201e\u00d8\u00b3\u00d9\u02c6\u00d8\u00b1\u00d9\u0160'
The actual word I store there for index is coding in another way:
'\xd8\xa7\xd9\x84\xd8\xb3\xd9\x88\xd8\xb1\xd9\x8a'
As you can tell, there is a one-to-to corresponding from \xd8↔\u00d8. But I don't know what is the name of this coding, thus I cannot convert it. And when I do the search as: <>/select/?q=السوري&wt=python,the response is:
{'responseHeader':{'status':0,'QTime':0,'params':{'wt':'python','q':u'\u0627\u0644\u0633\u0648\u0631\u064a'}},'response':{'numFound':0,'start':0,'docs':[]}}
No docs found and it seems using a third version for coding u'\u0627\u0644\u0633\u0648\u0631\u064a'. if I take it and encode('utf8') then it convert back to '\xd8\xa7\xd9\x84\xd8\xb3\xd9\x88\xd8\xb1\xd9\x8a'.
In summary, when it (السوري) is in my code (python) or in data base (mysql),
it presents as 'form1':
'\xd8\xa7\xd9\x84\xd8\xb3\xd9\x88\xd8\xb1\xd9\x8a'
When it is indexed by Solr, it converts to form2:
'\u00d8\u00a7\u00d9\u201e\u00d8\u00b3\u00d9\u02c6\u00d8\u00b1\u00d9\u0160'
And when I use <>/select/?q=السوري&wt=python, to query from browser (Google chrome), it becomes form3:
'\u0627\u0644\u0633\u0648\u0631\u064a'
(which could convert back to form1 by encode('utf8') But since they are different, the search matches nothing.
Therefore, those three different encode strategy may be the core problem. Could anyone help me figure it out and solve the search problem?
Thanks in advance.

How do I Benchmark RESTful Service with Variable Parameters?

I'm currently working on benchmarking a RESTful service I've made, and part of that is making sure it runs in a reasonable amount of times for a large array of parameters. For example, let's say I have RESTful API of the form some_site.com/item?item_id=y. In that case to be sure my service is working as fast as I'd like it to work, I'd want to try out many values for y one by one, preferably coming from some text file. I can't figure out any way of doing this in ab or httperf. I'm open to using a different benchmarking program if I have, but would prefer something simple and light. What I want to do seems like something pretty standard, so I'm guessing there must already be a program that let's me do it, but an hour or so of googling hasn't gotten me an answer. Ideas?
Answer: Jmeter (which is apparently awesome). This faq explains how to do it. Hopefully this helps someone else, as it took me like a day of searching to figure this out.
I have just had some good experience with using JavaScript (via BSF/Rhino) in JMeter.
I have put one thread group in my test plan and stick a 'Simple Controller' with two elements under it - 'HTTP Request' sampler and 'BSF PreProcessor'.
Set BSF language to 'javascript' and either type the code into the text box or point it to a file (use full path or relative to CWD of JMeter process).
/* Since `Math.random()` gives us float, we use `java.util.Random()`
* see: http://docs.oracle.com/javase/7/docs/api/java/util/Random.html */
var Random = new Packages.java.util.Random();
var min = 10-1;
var max = 2;
var maxLines = (min)+Random.nextInt(max-min);
var s = '';
for (var d = 0; d <= maxLines; d++) {
s += d.toString()+','+Random.nextInt(1000).toString()+'\n';
}
// s => '0,312\n1,104\n2,608\n'
vars.put('PAYLOAD', s);
Now I can refer to ${PAYLOAD} in the HTTP request!
You can generate JSON, but you will need to upgrade jakarta-jmeter-2.5.1/lib/js-1.6R5.jar with the newest version of Rhino to get JSON.stringify and JSON.parse. That worked perfectly for me also, though I thought I'd put a simple example here.
You can use BSF pre-processor for URL params as well, just set another variable with vars.put('X', 'some value') and pass it as ${X} in the request parameter.
This blog post helped quite a bit, by the way.