pg-promise 不理解 UTF 密码?..我不能让它与他们一起工作。在 linux 和 osx、postgres 9.3、9.5 上试过 - 似乎不特定于版本。查看代码。 pg-promise 使用 pg ,它使用 pg-connect-string这是基于 back pg 构建的.找不到问题的根源。请帮忙。
重现代码:
MacBook-Air:js vao$ cat 2.js
var pgp = require("pg-promise")(); var cs = 'postgresql://utf:утф@127.0.0.1:5433/a'; var db = pgp(cs); db.connect() .then(function (obj) { obj.done(); // success, release the connection; }) .catch(function (error) { console.log("ERROR:", error.message || error); }); console.log(cs);
返回:
MacBook-Air:js vao$ node 2.js
postgresql://utf:утф@127.0.0.1:5433/a ERROR: password authentication failed for user "utf"
使用与psql
相同的连接字符串:
MacBook-Air:js vao$ psql 'postgresql://utf:утф@127.0.0.1:5433/a'
psql (9.5.3) Type "help" for help. a=> \q
故意使用相同的连接字符串尝试错误的密码:
MacBook-Air:js vao$ psql 'postgresql://utf:утфWrongPassword@127.0.0.1:5433/a'
psql: FATAL: password authentication failed for user "utf" MacBook-Air:js vao$
最佳答案
作为 pg-promise 的作者,我想至少在这里提供一些关于在哪里查看的指导,而不是确切的答案,因为我自己从未处理过 UTF 密码。
pg-promise使用 node-postgres ,它又使用 pg-connection-string解析连接。如果有问题,那么它很可能在 pg-connection-string 内部.
我建议尝试依赖于 %
的 Unicode 表示法。也许它会起作用。也许不是,我从未尝试过。此外,以下问题从未得到回答:Node.js postgres UTF connect string ,这也不能令人放心。
抱歉,目前我帮不上什么忙。
关于node.js - pg-promise UTF 连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40964167/