I have a web service that accepts R code as string, executes it, serialize the results and sends it back as string which is then unserialized and displayed in R console. Based on some logic R code is built dynamically as string. The String R code is sent to the web service using curl. Body of the curl will have the string R code as one parameter.
When there is an assignment operator "<" in the Curl Body, web service never receives the parameter value.
When I print the Curl body I see the R code constructed correctly. I found that the issue with the assignment operator in the body.
E.g. summary(iris) works well
this code fails
x<- summary(iris)
x
Anyone know how to overcome this issue?
here is the sudo code
strrcode <- "x<-summary(iris) \n x"
body <- paste('<?xml version="1.0" encoding=""?>
<soap:Envelope xmlns="urn:xxx:xx:xxxx" xmlns:SOAP-
ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Info>
<id>', ID , '</Wuid>
<Cluster>', targetCluster , '</Cluster>
<Rcode>', strrcode , '</Rcode>
</Info>
</soap:Body>
</soap:Envelope>', sep="")
Related
[This is a duplicate post from NiceHash's GitHub in an attempt to broaden the audience. If I find a solution, at least others will also be able to see it in more places too]
Hi all,
I'm a newbie and the only language I know a little of is R.
I've managed to get a number of other APIs working under R using syntax like this:
# Account Stats
response <- httr::GET(
url = "https://API_URL_GOES_HERE",
)
I think I've got the gist of the syntax for R, but I'm having problems with hashing the Secret Key.
My API key / secret works with the "Try it out" link here.
But I get the usual invalid / 2000 error when passing my hashed secret key via the API.
Here's how I'm trying to generate the hashed secret key:
input <- paste0(APIKey," ", XTime," ", XNonce," "," ", OrgID," ", " ", "GET"," ", "/main/api/v2/accounting/accounts2", " ")
# Needs hashed?
APISecret <- hmac(input, "My_Secret_Key", "sha256")
XAuth <- paste0(APIKey, ":", APISecret)
And here's my API call:
# Account Stats
response<- httr::GET(
url = "https://api2.nicehash.com/main/api/v2/accounting/accounts2",
httr::add_headers(
`X-Time` = XTime,
`X-Nonce` = XNonce,
`X-Organization-Id` = OrgID,
#`X-Request-Id` = XNonce,
`X-Auth`= XAuth,
`Content-Type` = "application/json; charset=utf-8"
)
)
My thoughts are:
input is not correctly formatted
HMAC() isn't generating what NiceHash expects
My GET() isn't structured quite right
Any ideas?
EDIT - Link here explains how the input is supposed to be structured.
EDIT - Link here is examples in other languages, which I can't fully translate to R. The code I've shown above is my attempt.
UPDATE - OK, I'm pretty sure it's something to do with the hashing of the input string.
Using this as input:
4ebd366d-76f4-4400-a3b6-e51515d054d6 ⊠ 1543597115712 ⊠ 9675d0f8-1325-484b-9594-c9d6d3268890 ⊠ ⊠ da41b3bc-3d0b-4226-b7ea-aee73f94a518 ⊠ ⊠ GET ⊠ /main/api/v2/hashpower/orderBook ⊠ algorithm=X16R&page=0&size=100
The following string:
fd8a1652-728b-42fe-82b8-f623e56da8850750f5bf-ce66-4ca7-8b84-93651abc723b
when hashed should lead to:
21e6a16f6eb34ac476d59f969f548b47fffe3fea318d9c99e77fc710d2fed798
But I cannot get that as output. I've no idea what to use in place of ⊠ when forming the input. Other language examples use "\x00", but R just errors with:
Error: nul character not allowed (line 1)
I'm relatively new to XQuery and I'm using a XML with the following format (MODSXML):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<modsCollection xmlns="http://www.loc.gov/mods/v3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.loc.gov/mods/v3
http://www.loc.gov/standards/mods/v3/mods-3-0.xsd">
<mods ID="ISI:000330282600027" version="3.0">
<titleInfo>
<title>{Minimum Relative Entropy for Quantum Estimation: Feasibility and General
Solution}</title>
</titleInfo>
I'm trying to retrieva all titles of the articles contained on the XML file. The expression I'm using is the following:
for $x in collection("ExemploBibtex")/"quantuminformation.xml"/modsCollection/mods/titleInfo/title
return <title>$x/text()</title>
When I try to run this expression on Base, I get the following error:
"[XPTY0019] Steps within a path expression must yield nodes; xs:string
found."
Can anybody tell me what's wrong? The result I was expecting was a list with all the titles in the document.
Okay, problem solved in the BaseX Mailing List :D
I needed to declare the namespace. So now I'm using:
declare namespace v3 ="http://www.loc.gov/mods/v3";
for $doc in collection('ExemploBibtex')
where matches(document-uri($doc), 'quantuminformation.xml')
return $doc/v3:modsCollection/v3:mods/v3:titleInfo/v3:title/text()
And it works.
The problem is here:
collection("ExemploBibtex")/"quantuminformation.xml"/modsCollection
This returns a string with content quantuminformation.xml for each file/root node in the ExemploBibtex collection, and then tries to perform an axis step on each of these strings -- which is not allowed.
It seems you want to access to document quantuminformation.xml within the collection ExemploBibtex. To open a specific file of a collection, use following syntax instead:
collection("ExemploBibtex/quantuminformation.xml")/modsCollection
I cut of the last axis steps for readability and keeping the code lines short; simply add them again, they're fine.
I am implementing an application on R and now I'm trying to use REST protocol to communicate with an external application interface. It allows the app because this interaction has indicated in its documentation. I'm using a library called RCurl. Specifically I am using the function httpPUT. I have no idea about I'm doing wrong, but there is no change in the parameter that I want to modify it. My function is:
httpput_power<-function(DF_DEVICE_IDE_value){
require(XML)
require(RCurl)
power<-""
host<-"http://localhost:3171/devices/"
id_devices<-DF_DEVICE_IDE_value[1,1]
reader<-"/reader/parameter/RF_READ_POWER"
half_url<-paste(host,id_devices,"")
full_url<-paste(half_url,reader,"")
url_reader<-gsub(" ","", full_url , fixed=TRUE)
request="14.5"
httpPUT(url_reader, request)
}
Does anyone know a library for REST in R?. I not sure if RCurl is the most suited to do this task.
then there is an example in the documentation for the application to do a PUT with REST:
PUT http://host_address:3161/devices/{device-id}/reader/parameter/
{PARAM_NAME}
The value of the parameter.
Example: 30.5
Example:
<result>
<class>
com.keonn.impl.protocol.DefaultISO18000_6CParameters$Filter
</class>
<noFilter>false</noFilter>
<active>false</active>
<truncate>UNSPECIFIED</truncate>
<mask>
<bank>EPC</bank>
<pointer>32</pointer>
<maskLength>2</maskLength>
<mask>FF00</mask>
</mask>
</result>
I'm sure the URL is generated correctly, and in my case the parameter is RF_READ_POWER
I have a perl script that was provided by a vendor, and that takes a series of parameters. I would like to call this via a Windows Shell object in ASP classic.
If I type the following in the cmd line on the web server, it works just fine:
path_to_perl\perl.exe path_to_pl\myfile.pl --arg1 "something" --arg2 "somethingelse"
If I do the following in ASP classic, it doesn't work:
strCMD = "path_to_perl\perl.exe path_to_pl\myfile.pl --arg1 ""something"" --arg2 ""somethingelse"""
Set objWShell = CreateObject("WScript.Shell")
Set objCmd = objWShell.Exec("cmd.exe /c " & strCMD)
The issue is that the argument have all sorts of special characters, so I need to quote them. I have read conflicting information as to how I should escape them - via a caret or a back-slash. Any help would be greatly appreciated!
Shoulf call Perl directly, like this:
system_call_test( 'c:/complete/path_to_pl/myfile.pl --arg1 "something" ... ' )
See the discussion here: How to call perl programs from ASP page
and aspecially the answers of Charles K. Clarkson here.
It will simplify the problem, as you will not have to deal with escaping characters
for ASP, CMD and Perl - all at the same time.
(in that discussion the problem was a syntax-error at the Perl-script, eventually,
but it still shows how to code it in ASP).
I am changing my code to use binds in XForms (which is better practice than using nodesets everywhere!) but I am getting errors.
The error message I receive is: "Error: XForms Error (8): id (data_criterion) does not refer to a bind element..."
From tutorials/guides I have been using, it seems as though this should work, but clearly I am missing something! (btw, I was modeling my binding code after the examples here: http://en.wikibooks.org/wiki/XForms/Bind)
I originally thought the problem was due to the fact I was using xf:select controls as opposed to xf:input like the examples, but even once I dumbed down my code to the most simplistic code, I still receive errors!
This is the model code I am using:
<xf:model id="select_data">
<xf:instance id="criteria_data" xmlns="">
<file>
<criteria>
<criterion></criterion>
</criteria>
</file>
</xf:instance>
<bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>
</xf:model>
As for the ui code, this is what I have:
<xf:input bind="data_criterion">
<xf:label>Enter criteria:</xf:label>
</xf:input>
The error message I receive is: "Error: XForms Error (8): id (data_criterion) does not refer to a bind element..."
Anyone have any insight to what the problem is? Also, is there any special usage of bindings and xf:select (with xf:itemset) controls that I should be aware of? (I am ultimately using a lot of xf:select controls on my form..)
Thanks in advance!
EDIT:
I ran the code through this validator, and I got this message (refers to the bind line):
"Warning: Should the following element have the XForms namespace applied?: bind (line 66)"
A couple of things you might want to change:
Not sure of this is the reason for the error, but the nodeset expression should be instance('criteria_data')/criteria/..., without file. Remember: instance() returns the root element, not the document node. (This one you took care by updating the question; good)
You are missing the xf on the bind. It should be: <xf:bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>.
See below a full example with your code, which works fine for me under Orbeon Forms:
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner">
<xhtml:head>
<xhtml:title>SO Bind</xhtml:title>
<xf:model id="select_data">
<xf:instance id="criteria_data" xmlns="">
<file>
<criteria>
<criterion>Gaga</criterion>
</criteria>
</file>
</xf:instance>
<xf:bind id="data_criterion" nodeset="instance('criteria_data')/criteria/criterion"/>
</xf:model>
</xhtml:head>
<xhtml:body>
<xf:input bind="data_criterion">
<xf:label>Enter criteria:</xf:label>
</xf:input>
</xhtml:body>
</xhtml:html>