1

我有一个flask应用程序可以运行并连接到compose.iorethinkdb上的远程数据库。该应用程序也部署到pythonanywhere.com,但此部署不断抛出以下错误:

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。

4

1 回答 1

3

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

这对我有用:

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

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

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

于 2016-09-13T12:15:56.827 回答