I am using python (ver. 2.7) in conjunction with Wolfram Language to create and build strings in a query language syntax. I have a successfully deployed an APIFunction that builds a query once parameters are specified and it is resent. I would like to populate these parameters with a python script that takes variable spoken input, then populates the request, and is then posted to the Wolfram API which is then resent. Here is what this looks like:

import requests

def wolfram_cloud():
    # query will be populated via spoken utterances; for now it's hard-coded for testing purposes
    query = ['VESSEL', 'EVENT', 'TRIGGERED', 'v', 'e']
    intent = dict(zip(['string1', 'string2', 'RelString', 'index1', 'index2'], query))
    url = "https://www.wolframcloud.com/objects/0fc91bfb-ef6e-489b-ad07-8e6c25da21bb"
    requests.post(url, data=intent)
    return r.text

Will requests.post work in this case? There is some documentation on something similar to this (directly taking the APIFunction and instead of using CloudDeploy[], deploying it via python) , but they are using a method different from requests which I'm not familiar with (I am fairly new to python and urllib has been largely replaced with requests; either way, it doesn't seem to populate the API request with a value for x anyway). If not (which has been the case so far, since I get nothing upon execution of this script), then why not; the Wolfram Cloud is still a bit of a mystery to me on how it works.

I know I can use the URL to the CloudObject when parameters are filled in and is sent for arequests.get, but that would mean that for every different utterance it would require a different CloudObject. I want the flexibility of being able to have many utterances that match the pattern in the CloudObject so I can have just the one URL, which is why I'm wondering if requests.post can fill in the parameters automatically, then resend the API request. I am basically hoping it can act like URLExecute would:

{"string1" -> "VESSEL", "string2" -> "EVENT" ...}, 
"Method" -> "POST"
  • 1
    $\begingroup$ I question whether this is the right place for this question, rather than stackoverflow. $\endgroup$
    – Feyre
    Jul 11 '16 at 20:54
  • $\begingroup$ @Feyre I thought about this before posting as well, but I figured that there are more folks here that have exposure to Wolfram Cloud than in stackoverflow. However if others prefer moving the question over there, than I'd be happy to do so $\endgroup$
    – Lame-Ov2.0
    Jul 11 '16 at 20:58
  • 1
    $\begingroup$ Technically this SE is about Mathematica, and this question isn't. Stackoverflow also gets a lot more visitors, which you'll want considering the esoteric nature of the question. No one has requested a move, but if I were you I'd hedge my bets and ask on both. $\endgroup$
    – Feyre
    Jul 11 '16 at 21:07
  • $\begingroup$ The question you need to investigate on stackoverflow is how to get python to include your parameters in the URL. If that doesn't solve you problem then edit the above question to show the APIFunction and python code, and the Mathamatica end of the problem can be addressed here. On the other hand if the python you get on stackoverflow just works, then I'm sure that others here would be interested in your answer to your own question. $\endgroup$ Jul 11 '16 at 22:00
  • $\begingroup$ My previous comment assumes that the URLExecute code posted in your question is actually working. If it's not, then my suggested stack overflow question may not be helpful. $\endgroup$ Jul 11 '16 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.