Encoding with 'idna' codec failed in RethinkDB
<p>I have a <code>flask</code> app that runs and connects to a remote <code>rethinkdb</code> database on <a href="https://www.compose.io" rel="nofollow">compose.io</a>. The app is also deployed to <a href="https://www.pythonanywhere.com" rel="nofollow">pythonanywhere.com</a>, but this deployment keeps throwing the following error:</p>

<pre><code>Traceback (most recent call last):
File "/home/user/.virtualenvs/venv/lib/python3.5/encodings/idna.py", line 165, in encode
    raise UnicodeError("label empty or too long")
UnicodeError: label empty or too long

...

rethinkdb.errors.ReqlDriverError: Could not connect to rethinkdb://[user]:[password]@aws-us-east-1-portal.1.dblayer.com:23232. Error: encoding with 'idna' codec failed (UnicodeError: label empty or too long)
</code></pre>

<p>The connection code looks exactly like this:</p>

<pre><code>conn = r.connect(host='aws-us-east-1-portal.1.dblayer.com',  
             port=23232,
             auth_key='[auth_key]',
             ssl={'ca_certs': './cacert'})
</code></pre>

<p>I'm not sure how to proceed from here.</p>

<p>Running Python 3.5.</p>

<p>The idna codec is attempting to convert your rethinkdb URL into an ascii-compatible equivalent string.</p>

<p>This worked for me:</p>

<pre><code>"rethinkdb://user:password@aws-us-east-1-portal.1.dblayer.com:23232".encode("idna")
</code></pre>

<p>So my guess is that some character/sequence of characters in your username or password is causing the issue. Try the connection with a (possibly bogus) very simple password and see if you get the same issue.</p>

<p>Alternatively, you could do the encode in a Python shell with the connection string and gradually simplify it until you identify the problematic piece(s).</p>

python flask rethinkdb pythonanywhere compose