问题
Hi All I have a scenario to handle through Python Scripts that requires reading a value from CSV file and using it in a CURL command (equivalent in python URLLIB) as follows: Here is the CSV file for eg:
one two three four
1 3 5 7
2 3 5 7
I wrote a very simple Python program as :
import csv
with open('Activity_PSR.csv','rU') as csvFile:
reader=csv.reader(csvFile,delimiter=',')
for row in reader:
print row[2]
csvFile.close()
Once I get the output of this column ,I want to store it in a variable and use it in a CURL command to POST Data. CURL command equiv I beleive is urlib.
Here is the CURL POST Command:
curl -v -X POST -d ‘{“Organization_Id___ORACO__Account_Order":300100051155060,"}' slcaf961.us.oracle.com:10615/crmCommonApi/resources/11.1.10/__ORACO__Order_c
-H "Content-Type:application/vnd.oracle.adf.resourceitem+json" --user “sales_representative”
And the urllib code I am planning to use:
import urllib2
data = '{“Organization_Id___ORACO__Account_Order":300100051155060"}'
url = 'slcad745.us.oracle.com:10618/crmCommonApi/resources/11.1.10/__ORACO__Order_c'
req = urllib2.Request(url, data, {'Content-Type': 'application/json'})
f = urllib2.urlopen(req)
for x in f:
print(x)
f.close()
In the data field here Instead of passing 300100051155060 directly I want to use the value I got from the CSV above and pass that as the Account-Id.
Here are my queries: 1)I am getting the specific column with Column header through the script.I want the output of just the elements without the column header.how to do that ? 2)How to pass the value I got from the CSV and pass it to the JSON payload as a parameter ? Need to store the value I got from CSV and store it in a Variable and pass it to the JSON payload/data as a parameter and execute the POST method. Request folks to help me on how to acheive the above scenario.Thank you for the help.
来源:https://stackoverflow.com/questions/31775208/reading-sepcific-csv-column-value-and-passing-it-to-curl-urllib-as-param-in-pyth