title: How to read data from csv file and parse to python POST requests as a dict format
body: <p>I want to read data from a CSV file and parse that into Python POST requests in a dictionary format which will create a content-type: <code>multipart/form-data auto</code> when sending a request to the API.</p>
  
  <p>I have tried</p>
  
  <pre class="lang-py prettyprint-override"><code>with open("listingData1.csv", "r") as f_input:
      csv_input = csv.DictReader(f_input)
  
      for row in csv_input:
          data_android = {
  
          'mailing_details': row["shipping"],
          'caroupay':'false',
          'price':row['price'],
          'description':row['desc'],
          'title':row['title'],
          'meetup':'false',
          'condition':'2',
          'mailing':'true',
          'collection_id':row['cat']
          }
          print(row)
          search_path = row['image']
          urls = []
          for file in os.listdir(os.getcwd()+search_path):
              if file.endswith((".jpg",".jpeg",".png",".JPG",".JPEG",".PNG")):
                  x = os.getcwd()+"\\"+search_path+"\\"+file
                  urls.append(x)
  
  
          files = {'photo_%s' % x: ('photo_%s.jpg' % x, open(file, 'rb'), 'image/jpeg') for x, file in enumerate(urls)}
          #print data_android
          response = requests.request("POST", url_and,data=data_android,headers=headers)
          print(response.text.encode("utf-8"))
  
  </code></pre>
  
  <p>However, requests send data to the API with <code>content-type:application/x-www-form-urlencoded</code> which is not accepted by the API:</p>
  
  <pre><code>'POST /api/3.0/listings/ HTTP/1.1\r
  Host: api.testdomain.com\r
  Connection: keep-alive\r
  Accept-Encoding: gzip, deflate\r
  Accept: */*\r
  User-Agent: python-requests/2.21.0\r
  platform: android\r
  Authorization: Token afs7dfa76sd8f7a68sd76f8as6fd8s\r
  Content-Length: 179\r
  Content-Type: application/x-www-form-urlencoded\r
  \r
  abcpay=FALSE&amp;description=test1&amp;mailing_details=FREE&amp;price=239.00&amp;title=Pet+Cat+Dog+Carrier+Portable+Breathable+Comfortable&amp;meetup=FALSE&amp;collection_id=45&amp;mailing=TRUE&amp;condition=2'
  </code></pre>
  
  <p>After that, I tried to use the default dictreader option from CSV module:</p>
  
  <pre><code>with open("listingData1.csv", "r") as f_input:
      csv_input = csv.DictReader(f_input)
  
      for row in csv_input:
          search_path = row['image']
          urls = []
          for file in os.listdir(os.getcwd()+search_path):
              if file.endswith((".jpg",".jpeg",".png",".JPG",".JPEG",".PNG")):
                  x = os.getcwd()+"\\"+search_path+"\\"+file
                  urls.append(x)
  
  
          files = {'photo_%s' % x: ('photo_%s.jpg' % x, open(file, 'rb'), 'image/jpeg') for x, file in enumerate(urls)}
          #print data_android
          response = requests.request("POST", url_and,data=row,headers=headers)
          print(response.text.encode("utf-8"))
  </code></pre>
  
  <p>which also gives the same output. Now, is there any way to parse CSV data into POST requests as a dictionary file?</p>
  
  <p>Here is my full code:</p>
  
  <pre><code>import requests
  import logging
  import os
  import json
  import csv
  
  try:
      import http.client as http_client
  except ImportError:
      # Python 2
      import httplib as http_client
  http_client.HTTPConnection.debuglevel = 1
  
  # You must initialize logging, otherwise you'll not see debug output.
  logging.basicConfig()
  logging.getLogger().setLevel(logging.DEBUG)
  requests_log = logging.getLogger("requests.packages.urllib3")
  requests_log.setLevel(logging.DEBUG)
  requests_log.propagate = True
  
  url_and = "https://api.test.com/api/3.0/listings/"
  
  android_token = '8fas8d7f9a8s7d9f87as9d8f7sa9df7s9f'
  headers = {
      'Authorization': "Token " + android_token,
      'platform': 'android',
  }
  
  data_android = {}
  
  with open("listingData1.csv", "r") as f_input:
      csv_input = csv.DictReader(f_input)
  
      for row in csv_input:
          data_android = {
          'mailing_details':row['shipping'],
          'abcoupay':'false',
          'price':row['price'],
          'description':row['desc'],
          'title':row['title'],
          'meetup':'false',
          'condition':'2',
          'mailing':'true',
          'collection_id':row['cat']
          }
  
          search_path = row['image']
          urls = []
          for file in os.listdir(os.getcwd()+search_path):
              if file.endswith((".jpg",".jpeg",".png",".JPG",".JPEG",".PNG")):
                  x = os.getcwd()+"\\"+search_path+"\\"+file
                  urls.append(x)
  
  
          files = {'photo_%s' % x: ('photo_%s.jpg' % x, open(file, 'rb'), 'image/jpeg') for x, file in enumerate(urls)}
  
          response = requests.request("POST", url_and,data=data_android,headers=headers)
          print(response.text.encode("utf-8"))
  </code></pre>