0

How to pass CSV file contents as parameter to web service in python.Now i am passing only 5 values to web service and inserting it to mongodb database. I am using soaplib web service and mongodb database,using soaplib load data to database. How to pass CSV file contents to web service and insert it to mongodb database?

Thanks

user27
  • 146
  • 1
  • 1
  • 8
  • i just passed values through command prompt,but now i want to send csv file content as parameter to web service and in web service i am storing data in mongodb database.how to do that? – user27 Mar 13 '13 at 04:55
  • 1
    Which driver you are using to connect to MongoDB? – Amol M Kulkarni Mar 13 '13 at 09:49

1 Answers1

0

Try out the following steps:

  1. Firstly locate the CSV file location, which is programmatically accessible from your Python. Consider it as path
  2. Go through this link, read the file similar to the example quoted in the linked article.

    Example:

    fo = open(path + "yourfile.csv", "r+")
    str = fo.read(10);     
    
  3. Open Connection to MongoDB with your mongo-python-driver

    Example:

    import pymongo
    client = pymongo.MongoClient("localhost", 27017)
    
  4. Then ultimately pass the content of the file, which you read in step

    Example: db.my_collection.save({"CSV_FileContent": Obj_CSV_File})

To pass your file content from your python program to a web service, you may try following:

Amol M Kulkarni
  • 21,143
  • 34
  • 120
  • 164