1

I have a flask app that runs and connects to a remote rethinkdb database on compose.io. The app is also deployed to pythonanywhere.com, but this deployment keeps throwing the following error:

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)

The connection code looks exactly like this:

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

I'm not sure how to proceed from here.

Running Python 3.5.

Glenn
  • 7,262
  • 1
  • 17
  • 23
Ally Jr
  • 1,055
  • 1
  • 14
  • 27
  • I'm confused as to where the "rethinkdb://[user]:[password]@aws-us-east-1-portal.1.dblayer.com:23232" string is coming from in the error message. Your `r.connect` code snippet doesn't contain that string, and the RethinkDB driver certainly will not generate a URI that looks like this. So it seems like the `r.connect` snippet doesn't match up with the error? – Daniel Mewes Sep 14 '16 at 19:00
  • As explained in the comment below, IDNA should apply only to (DNS) names, and it handles labels (something between two dots) so your string is split on dots and then each label must be up to 63 bytes in length, so the `rethinkdb://[user]:[password]@aws-us-east-1-portal` part, considered as the first label, is probably over 63 characters (as soon as user + password parts are over 28 characters together – Patrick Mevzek Feb 14 '20 at 19:19

1 Answers1

3

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

This worked for me:

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

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.

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).

Glenn
  • 7,262
  • 1
  • 17
  • 23
  • Technically the IDNA encoding should apply only on the hostname, and nothing else. Otherwise you will get unexpected results: `u"rethinkdb://user:café@example.com".encode("idna")` yields `'xn--rethinkdb://user:caf@example-urc.com'` which does not make sense anymore (which is why I think the OP question is lacking some details I doubt that it can has the error shown with what was given). – Patrick Mevzek Feb 12 '20 at 17:59