title: Python Rest client api to upload a file
body: <p>I am using Python 2.7. My Rest server side API works fine and I am able to upload a zip file using Postman. I am trying to upload a zip file using Rest client api. I tried requests package, but it is unable to send the files. I am getting an error : missing file argument. </p>
  
  <p>This is my python server side code :</p>
  
  <pre><code>@ns.route('/upload_file', strict_slashes=False)
  class Upload(Resource):
      @api.expect(upload_parser)
      def post(self):
  
          args = upload_parser.parse_args()
          file_nameup = args.file.filename 
  </code></pre>
  
  <p>Here is the rest api client code :</p>
  
  <pre><code>import requests
  from requests.auth import HTTPBasicAuth
  import json
  
  headers={'Username': 'abc@gmail.com', 'apikey':'123-e01b', 'Content-Type':'application/zip'}
  f = open('C:/Users/ADMIN/Downloads/abc.zip', 'rb')
  
  files = {"file": f}
  
  resp = requests.post("https://.../analytics/upload_file", files=files, headers=headers )
  
  print resp.text   
  
  print "status code " + str(resp.status_code)
  
  if resp.status_code == 200:
      print ("Success")
      print resp.json()
  else:
      print ("Failure")
  </code></pre>
  
  <p>This is my error :
      {"message":"Input payload validation failed","errors":{"file":"Missing required
      parameter in an uploaded file"}
      status code 400
      Failure</p>
  
  <p>In postman, I passed a zip file with in body with "file" as key and value as abc.zip file. It worked fine.  I tried to use httplib library, but it fails as my post url does not contain port number. This the error with httplib :</p>
  
  <blockquote>
    <p>python HttpClientEx.py
        Traceback (most recent call last):
          File "HttpClientEx.py", line 4, in 
            h = http.client.HTTPConnection(url)
          File "c:\python27\Lib\httplib.py", line 736, in <strong>init</strong>
            (self.host, self.port) = self._get_hostport(host, port)
          File "c:\python27\Lib\httplib.py", line 777, in _get_hostport
            raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
        httplib.InvalidURL: nonnumeric port: '// ....net/analytics/upload_file'</p>
  </blockquote>
  
  <p>How to invoke rest url post and upload a file using urllib library. Please suggest any other ways to upload file in rest client. Thanks.  </p>
  
  <p>I found another duplicate post :</p>
  
  <p><a href="https://stackoverflow.com/questions/18208109/python-requests-post-a-zip-file-with-multipart-form-data">Python Requests - Post a zip file with multipart/form-data</a></p>
  
  <p>The solution mentioned there did not work. I found that you need to provide the full path of the file, otherwise it will not work. </p>