0
votes

I need to make the following curl command within a python program. This trains a classifier.

curl -i --user "{username}":"{password}" -F training_data=@{path_to_file}/weather_data_train.csv -F training_metadata="{\"language\":\"en\",\"name\":\"TutorialClassifier\"}" "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers"

After that, I need my program to make another curl command which queries the previously trained classifier. This query returns some results that I need my program to be able to access and use

curl --user "{username}":"{password}" "https://gateway.watsonplatform.net/natural-language-classifier/api/v1/classifiers/{classifier_id}"

Just entering these commands manually in the terminal works but I need to automate the process using a python or java program . Thanks for any help!

2
Have you read through the Requests documentation? That's pretty straightforward. There are several different ways to achieve what you want, but your question is at this point far too broad. - Shawn Mehan
Welcome to Stack Overflow! Please take the tour, have a look around, and read through the help center, in particular How do I ask a good question?. - Raquel GuimarĂ£es
Have you tried PyCurl? Curl library for python. pycurl.io/docs/latest - Kim Clarence Penaflor

2 Answers

0
votes

I have done this sort of thing with python. Look at the standard packaged urllib2. I have used this to extract rates from the Eurapean Central Bank:

import urllib2 response = urllib2.urlopen("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml")

Response now contains an the xml response returned from the ECB.
Other useful modules are urlparse, xml.dom and elementree for xml processing.

0
votes

I also recommend using Requests.

But if you have working curl commands and you want to access their output for further processing you can use subprocess, e.g.

import subprocess
curl_cmd = "..."
output = subprocess.check_output(curl_cmd)