title: Understanding and Interacting with API using Python
body: <p>I have a basic API installed as my localhost server that does functions such as add camera, star camera, list cameras, snapshot of camera frame, etc.</p>
  
  <p>My problem is after following the documentation I still can't seem to interact with it well and get the response I need. Here is the code I use to log in and get validation token:</p>
  
  <pre><code>import requests
  import urllib.request
  import json
  
  
  base_url = "http://localhostip:8080/api/user/login?"
  parameters = {
      "username": username,
      "password": password
  }
  auth_tok = requests.post(base_url + urllib.parse.urlencode(parameters)).json()
  print(auth_tok)
  </code></pre>
  
  <p>I get the correct documented response with a token, so following the documentation to add camera I need 2 parameters, <code>URL</code> and <code>Name</code>, so I did:</p>
  
  <pre><code>base_url = "http://localhostip:8080/api/camera/add?"
  
  parameters = {
  
      "url": 'rtsp://192.168.1.23/1', 
  
      #or video file 
      "url" : '/home/video/sample.mov'
  
      "name" : 'cam1'
  
  }
  r = requests.post(base_url + urllib.parse.urlencode(parameters),headers={'Authorization': auth_tok})
  </code></pre>
  
  <p>when I print the response:</p>
  
  <pre><code>-print (r)
  -print (r.url)
  -print(r.status_code)
  -print(r.json())
  </code></pre>
  
  <p>I get this:</p>
  
  <pre><code>&lt;Response [500]&gt;
  
  http://192.168.0.162:8080/service/api/camera/add?url=rtsp%3A%2F%2Frtsp%3A%2F%2F192.168.1.23&amp;name=cam1
  
  500
  
  {'code': -111, 'message': None}
  </code></pre>
  
  <p>According to documentation the correct url should be like this:</p>
  
  <pre><code>http://192.168.0.6:8080/service/api/camera/add?url=rtsp://192.168.1.23&amp;name=cam1
  </code></pre>
  
  <p>and the response should be:</p>
  
  <p><code>Response:
  {"status":"ok"}</code></p>
  
  <p>So why and how to make the URL POST in the correct format, because I suspect this is the issue, the URL has these encoding symbols that may be messing up the request?</p>
  
  <p>When I use the web browser GUI of this API I can add the camera or even a video file to play but I'm trying to do the same with Python so I can do further processing in future.</p>