title: digitalocean script error on call
body: <p>Im Using digitalocean script on centos, however it does not seem to work.
  <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-highly-available-haproxy-servers-with-keepalived-and-floating-ips-on-ubuntu-14-04" rel="nofollow">https://www.digitalocean.com/community/tutorials/how-to-set-up-highly-available-haproxy-servers-with-keepalived-and-floating-ips-on-ubuntu-14-04</a></p>
  
  <p><code>Traceback (most recent call last):
      File "/usr/local/bin/assign-ip", line 33, in &lt;module&gt;
      usage()
     File "/usr/local/bin/assign-ip", line 12, in usage
      print('{} [Floating IP] [Droplet ID]'.format(sys.argv[0]))
     ValueError: zero length field name in format
  </code></p>
  
  <p>here is sh script to call</p>
  
  <pre><code>` export DO_TOKEN='xxxxxxxxxxx'
  IP='xxx.xxx.xxx.xxx'
  ID=$(curl -s 169.254.169.254/metadata/v1/id)
  HAS_FLOATING_IP=$(curl -s http://169.254.169.254/metadata/v1/floating_ip/ipv4/active)
  
  if [ $HAS_FLOATING_IP = "false" ]; then
  n=0
  while [ $n -lt 10 ]
  do
      python /usr/local/bin/assign-ip $IP $ID &amp;&amp; break
      n=$((n+1))
      sleep 3
  done
  fi`
  </code></pre>
  
  <p>here is the assign-ip script</p>
  
  <pre><code>`#!/usr/bin/python
  
  import os
  import sys
  import requests
  import json
  
  api_base = 'https://api.digitalocean.com/v2'
  
  
  def usage():
  print('{} [Floating IP] [Droplet ID]'.format(sys.argv[0]))
  print('\nYour DigitialOcean API token must be in the "DO_TOKEN"'
        ' environmental variable.')
  
  
  def main(floating_ip, droplet_id):
  payload = {'type': 'assign', 'droplet_id': droplet_id}
  headers = {'Authorization': 'Bearer {}'.format(os.environ['DO_TOKEN']),
             'Content-type': 'application/json'}
  url = api_base + "/floating_ips/{}/actions".format(floating_ip)
  r = requests.post(url, headers=headers,  data=json.dumps(payload))
  
  resp = r.json()
  if 'message' in resp:
      print('{0}: {1}'.format(resp['id'], resp['message']))
      sys.exit(1)
  else:
      print('Moving IP address: {}'.format(resp['action']['status']))
  
  if __name__ == "__main__":
  if 'DO_TOKEN' not in os.environ or not len(sys.argv) &gt; 2:
      usage()
      sys.exit()
  main(sys.argv[1], sys.argv[2])
  `
  </code></pre>