在 RethinkDB 中使用 'idna' 编解码器编码失败

Encoding with 'idna' codec failed in RethinkDB

我有一个 flask 应用程序运行并连接到 compose.io. The app is also deployed to pythonanywhere.com 上的远程 rethinkdb 数据库,但此部署不断抛出以下错误:

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)

连接代码看起来完全像这样:

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

我不确定如何从这里开始。

运行 Python 3.5.

idna 编解码器正在尝试将您的 rethinkdb URL 转换为与 ascii 兼容的等效字符串。

这对我有用:

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

所以我的猜测是您的用户名或密码中的某些 character/sequence 个字符导致了问题。尝试使用(可能是伪造的)非常简单的密码进行连接,看看是否遇到同样的问题。

或者,您可以使用连接字符串在 Python shell 中进行编码并逐渐简化它,直到您找出有问题的部分。