问题
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.
回答1:
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).
来源:https://stackoverflow.com/questions/39465259/encoding-with-idna-codec-failed-in-rethinkdb