title: Send a file in python
body: <p>I have looked every where on the net on how to send a file in python, 100% is a fail, no one can help. Are there any programmers out there that can help me send a file from client to server or the other way?</p>
  
  <p>I can send txt very easy</p>
  
  <pre><code>#!/usr/bin/python
  """
  Socket Client
  """
  import socket #networking library
  indent = ""
  server = input("server name (default is " + socket.gethostname() + "): ") or socket.gethostname()
  
  print("connecting to server at: %s" % server)
  
  while True:
      clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
  
      clientSocket.connect((server, 23000)) 
  
  
  
      str = input("text to send: ")
  
      clientSocket.send(str.encode("utf-8")) #send text as encoded bytes
  
      print("received: %s" % clientSocket.recv(100).decode("utf-8")) 
  
      clientSocket.close()
  
      #strRecv = clientSocket.recv(500).decode("utf-8") #receive up to 500 bytes and decode into text
      #print(strRecv)
  </code></pre>