AWS.Client raised PROGRAM_ERROR : aws-client.adb:543 finalize/adjust raised exception
AWS.Client raised PROGRAM_ERROR : aws-client.adb:543 finalize/adjust raised exception
我正在尝试编写一个简单的 Ada(使用 AWS)程序将 post 数据发送到服务器。 curl 命令的工作方式如下,成功登录后 return 在 JSON 中的有效响应:
curl -XPOST -d '{"type":"m.login.password", "user":"xxx", "password": "xxxxxxxxxx"}' "https://matrix.org/_matrix/client/r0/login"
我的 Ada 程序:
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_Io; use Ada.Text_IO;
with AWS.Client;
with AWS.Communication.Client;
with AWS.MIME;
with AWS.Net;
with AWS.Response;
use AWS;
procedure Communicate is
Result : Response.Data;
Data : String := "{""type"":""m.login.password"", ""user"":""xxx"", ""password"": ""xxxxxxxxxx""}";
begin
Result := Client.Post
( URL => "https://matrix.org/_matrix/client/r0/login",
Data => Data,
Content_Type => AWS.MIME.Application_JSON ) ;
Put_Line ( Response.Message_Body ( Result ) ) ;
end Communicate;
出现异常。我不知道这段代码有什么问题。
$ ./Communicate
raised PROGRAM_ERROR : aws-client.adb:543 finalize/adjust raised exception
要测试代码,您可以在 http://matrix.org 创建一个帐户并替换登录凭据。
谢谢。
阿德里安
经过一些小改动(主要是因为我不喜欢编译器警告),并适应了 AWS 的 Debian/Jessie 版本,我开始使用它了。
改编版如下:
with Ada.Text_IO; use Ada.Text_IO;
with AWS.Client;
-- with AWS.MIME;
with AWS.Response;
use AWS;
procedure Communicate is
Result : Response.Data;
Data : constant String :=
"{""type"":""m.login.password"", ""user"":""xxx"", " &
"""password"": ""xxxxxxxxxx""}";
begin
Result := Client.Post
(URL => "https://matrix.org/_matrix/client/r0/login",
Data => Data,
Content_Type => "application/json");
-- Content_Type => AWS.MIME.Application_JSON);
Put_Line (Response.Message_Body (Result));
end Communicate;
这是我的项目文件:
with "aws";
project Communicate is
for Main use ("communicate");
package Builder is
for Default_Switches ("Ada")
use ("-m");
end Builder;
package Compiler is
for Default_Switches ("Ada")
use ("-fstack-check", -- Generate stack checking code (part of Ada)
"-gnata", -- Enable assertions (part of Ada)
"-gnato13", -- Overflow checking (part of Ada)
"-gnatf", -- Full, verbose error messages
"-gnatwa", -- All optional warnings
"-gnatVa", -- All validity checks
"-gnaty3abcdefhiklmnoOprstux", -- Style checks
"-gnatwe", -- Treat warnings as errors
"-gnat2012", -- Use Ada 2012
"-Wall", -- All GCC warnings
"-O2"); -- Optimise (level 2/3)
end Compiler;
end Communicate;
我用以下方法构建程序:
% gprbuild -P communicate
gnatgcc -c -fstack-check -gnata -gnato13 -gnatf -gnatwa -gnatVa -gnaty3abcdefhiklmnoOprstux -gnatwe -gnat2012 -Wall -O2 communicate.adb
gprbind communicate.bexch
gnatbind communicate.ali
gnatgcc -c b__communicate.adb
gnatgcc communicate.o -L/usr/lib/x86_64-linux-gnu -lgnutls -lz -llber -lldap -lpthread -o communicate
%
然后测试:
% ./communicate
{"errcode":"M_FORBIDDEN","error":"Invalid password"}
%
看来问题出在您的 AWS version/installation。
通过使用来自 MacPorts 的 gnutls 构建 AWS 解决了问题。 Apple 自 OS X Lion 开始弃用 OpenSSL 并使用 CommonCrypto,因此现代 macOS 不附带 OpenSSL。解决方案是从 Mac Ports 或 Home Brew 下载并安装 OpenSSL 或 gnutls。
另外一个问题是Apple从El Capitan开始引入了SIP(System Integrity Protection)。启用SIP后,具有管理员权限的用户无法更改/usr/include和/usr/lib等中的内容
Mac Ports 安装到 /opt/local 所以我引用了 /opt/local/include 和 /opt/local/lib 以便 AWS 可以使用 OpenSSL 或 gnutls 构建。
我正在尝试编写一个简单的 Ada(使用 AWS)程序将 post 数据发送到服务器。 curl 命令的工作方式如下,成功登录后 return 在 JSON 中的有效响应:
curl -XPOST -d '{"type":"m.login.password", "user":"xxx", "password": "xxxxxxxxxx"}' "https://matrix.org/_matrix/client/r0/login"
我的 Ada 程序:
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_Io; use Ada.Text_IO;
with AWS.Client;
with AWS.Communication.Client;
with AWS.MIME;
with AWS.Net;
with AWS.Response;
use AWS;
procedure Communicate is
Result : Response.Data;
Data : String := "{""type"":""m.login.password"", ""user"":""xxx"", ""password"": ""xxxxxxxxxx""}";
begin
Result := Client.Post
( URL => "https://matrix.org/_matrix/client/r0/login",
Data => Data,
Content_Type => AWS.MIME.Application_JSON ) ;
Put_Line ( Response.Message_Body ( Result ) ) ;
end Communicate;
出现异常。我不知道这段代码有什么问题。
$ ./Communicate
raised PROGRAM_ERROR : aws-client.adb:543 finalize/adjust raised exception
要测试代码,您可以在 http://matrix.org 创建一个帐户并替换登录凭据。
谢谢。
阿德里安
经过一些小改动(主要是因为我不喜欢编译器警告),并适应了 AWS 的 Debian/Jessie 版本,我开始使用它了。
改编版如下:
with Ada.Text_IO; use Ada.Text_IO;
with AWS.Client;
-- with AWS.MIME;
with AWS.Response;
use AWS;
procedure Communicate is
Result : Response.Data;
Data : constant String :=
"{""type"":""m.login.password"", ""user"":""xxx"", " &
"""password"": ""xxxxxxxxxx""}";
begin
Result := Client.Post
(URL => "https://matrix.org/_matrix/client/r0/login",
Data => Data,
Content_Type => "application/json");
-- Content_Type => AWS.MIME.Application_JSON);
Put_Line (Response.Message_Body (Result));
end Communicate;
这是我的项目文件:
with "aws";
project Communicate is
for Main use ("communicate");
package Builder is
for Default_Switches ("Ada")
use ("-m");
end Builder;
package Compiler is
for Default_Switches ("Ada")
use ("-fstack-check", -- Generate stack checking code (part of Ada)
"-gnata", -- Enable assertions (part of Ada)
"-gnato13", -- Overflow checking (part of Ada)
"-gnatf", -- Full, verbose error messages
"-gnatwa", -- All optional warnings
"-gnatVa", -- All validity checks
"-gnaty3abcdefhiklmnoOprstux", -- Style checks
"-gnatwe", -- Treat warnings as errors
"-gnat2012", -- Use Ada 2012
"-Wall", -- All GCC warnings
"-O2"); -- Optimise (level 2/3)
end Compiler;
end Communicate;
我用以下方法构建程序:
% gprbuild -P communicate
gnatgcc -c -fstack-check -gnata -gnato13 -gnatf -gnatwa -gnatVa -gnaty3abcdefhiklmnoOprstux -gnatwe -gnat2012 -Wall -O2 communicate.adb
gprbind communicate.bexch
gnatbind communicate.ali
gnatgcc -c b__communicate.adb
gnatgcc communicate.o -L/usr/lib/x86_64-linux-gnu -lgnutls -lz -llber -lldap -lpthread -o communicate
%
然后测试:
% ./communicate
{"errcode":"M_FORBIDDEN","error":"Invalid password"}
%
看来问题出在您的 AWS version/installation。
通过使用来自 MacPorts 的 gnutls 构建 AWS 解决了问题。 Apple 自 OS X Lion 开始弃用 OpenSSL 并使用 CommonCrypto,因此现代 macOS 不附带 OpenSSL。解决方案是从 Mac Ports 或 Home Brew 下载并安装 OpenSSL 或 gnutls。
另外一个问题是Apple从El Capitan开始引入了SIP(System Integrity Protection)。启用SIP后,具有管理员权限的用户无法更改/usr/include和/usr/lib等中的内容
Mac Ports 安装到 /opt/local 所以我引用了 /opt/local/include 和 /opt/local/lib 以便 AWS 可以使用 OpenSSL 或 gnutls 构建。