title: How to use Asterisk AGI with python3?
body: <p>Using  Asterisk 16.2.1 my <code>AGI</code> script (at the bottom) works with python2 <code>#!/usr/bin/env python2</code>, but not with python3 <code>#!/usr/bin/env python3</code>.</p>
  
  <p>I do not even get as far as <code>agi.verbose("python agi started")</code> (with python3), so I assume it has something to do with the AGI import or initialization <code>agi = AGI()</code> </p>
  
  <p>Having used <code>agi set debug on</code> does not really help, the only info I see is</p>
  
  <pre><code>Launched AGI Script /home/.../asteriskAgi.py
      -- &lt;SIP/..-00000002&gt;AGI Script /home/.../asteriskAgi.py completed, returning 0
  </code></pre>
  
  <p>As it works with python2, but not 3 I have also installed <code>pyst3</code> from <a href="https://pypi.org/project/pyst3/" rel="nofollow noreferrer">https://pypi.org/project/pyst3/</a> , but it did not help (it does not work with or without <code>pyst3</code> installed).</p>
  
  <p><strong>Q:</strong> Any idea how to configure <code>asterisk</code> for python3, or how to find the root cause?
  Any chance to get more detailed log information of where the script actually fails_</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import sys
  import rpyc
  
  from asterisk.agi import AGI
  
  agi = AGI()
  agi.verbose("python agi started")
  aCallerId = agi.env['agi_callerid']
  aType = agi.env["agi_type"]
  agi.verbose("XXXXXXXXXXXXXX call from %s" % aCallerId)
  agi.verbose(sys.executable)
  
  l = [aCallerId, aType]
  agi.verbose("XXXXXXXXXXXXXX l")
  
  c = rpyc.connect("localhost", 18861)
  c.root.asteriskCall(l)
  </code></pre>
  
  <hr>
  
  <p>Even this minimalistic version does not work with "3"</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import rpyc
  
  from asterisk.agi import AGI
  
  agi = AGI()
  agi.verbose("python agi started")
  </code></pre>
  
  <hr>
  
  <p>eventually solved by:</p>
  
  <ol>
  <li>uninstalled <code>pyst3</code> and </li>
  <li>forced a re-install of <code>pyst2</code> like <code>pip3 install --upgrade --force-reinstall pyst2</code>. No idea what went wrong in the first place.</li>
  </ol>