8

Elixir と Erlang は初めてで、https URL へのアクセスに問題があります。Elixir 固有のHTTPotionと Erlang の:inetsモジュールを試しました。

したがって、iex コンソール (インタラクティブ Elixir) から:

HTTPotion を使用する場合:

HTTPotion.start
HTTPotion.get("https://api.github.com")

:inet を使用:

:inets.start
:ssl.start
:httpc.request('https://api.github.com')

どちらの場合も、どこかに悪い一致があり、ステートマシンが終了していることを示す巨大なスタックトレースが得られます。http URL にアクセスするときは、これを取得できません。私は何が欠けていますか?ありがとう。

編集 - HTTPotion からのエラー メッセージは次のとおりです。

iex(40)> HTTPotion.get("https://api.github.com") 
** (Protocol.UndefinedError) protocol String.Chars not implemented for {:EXIT, {{{{:badmatch, ""}, [{:ssl_handshake, :dec_hello_extensions, 2, [file: 'ssl_handshake.erl', line: 1737]}, {:ssl_handshake, :decode_handshake, 3, [file: 'ssl_handshake.erl', line: 926]}, {:tls_handshake, :get_tls_handshake_aux, 3, [file: 'tls_handshake.erl', line: 155]}, {:tls_connection, :next_state, 4, [file: 'tls_connection.erl', line: 433]}, {:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 503]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 237]}]}, {:gen_fsm, :sync_send_all_state_event, [#PID<0.227.0>, {:start, 5000}, :infinity]}}, {:gen_server, :call, [#PID<0.226.0>, {:send_req, {{:url, 'https://api.github.com', 'api.github.com', 443, :undefined, :undefined, '/', :https, :hostname}, [], :get, "", [], 5000}}, 5000]}}}
       (elixir) lib/string/chars.ex:3: String.Chars.impl_for!/1
       (elixir) lib/string/chars.ex:17: String.Chars.to_string/1
    (httpotion) lib/httpotion.ex:157: HTTPotion.request/5
iex(40)> 
16:50:10.640 [error] ** State machine #PID<0.227.0> terminating 
** Last message in was {:tcp, #Port<0.7454>,
 <<22, 3, 3, 0, 93, 2, 0, 0, 89, 3, 3, 84, 40, 158, 178, 2, 216, 45, 226, 183, 79, 42, 199, 205, 19, 31, 63, 223, 138, 208, 132, 186, 28, 129, 123, 235, 1, 142, 90, 243, 25, 70, 210, 32, 199, 56, 251, 131, ...>>}
** When State == :hello
**      Data  == [data: [{'StateData',
   {:state, :client, {#Reference<0.0.0.1360>, #PID<0.226.0>}, :gen_tcp,
    :tls_connection, :tcp, :tcp_closed, :tcp_error, 'api.github.com', 443,
    #Port<0.7454>,
    {:ssl_options, :tls, [{3, 3}, {3, 2}, {3, 1}, {3, 0}], :verify_none,
     {#Function<7.50551058/3 in :ssl.handle_verify_options/2>, []},
     #Function<8.50551058/1 in :ssl.handle_verify_options/2>, false, false,
     :undefined, 1, "", '***', "", '***', '***', '***', "", '***', :undefined,
     :undefined, '***', '***',
     [<<192, 36>>, <<192, 40>>, <<192, 38>>, <<192, 42>>, <<0, 107>>,
      <<0, 106>>, <<0, 61>>, <<192, 35>>, <<192, 39>>, <<192, 37>>, <<192, 41>>, 
      <<0, 103>>, <<0, ...>>, <<...>>, ...],
     #Function<1.50551058/4 in :ssl.handle_options/1>, true, 268435456, false,
     :undefined, false, :undefined, :undefined, true, :undefined, false},
    {:socket_options, :binary, 0, 0, 0, false}, '***', '***', '***', 49168,
    '***', 61463, :ssl_session_cache, {3, 3}, false, :undefined,
    {:undefined, :undefined}, :undefined, :undefined, '***', '***', '***',
    :undefined, '***', '***', '***', 53269, #Reference<0.0.0.1363>, :undefined,
    '***', {false, :first}, {#PID<0.226.0>, #Reference<0.0.0.1361>},
    #Reference<0.0.0.1364>, {[], []}, false, true, false, false, :undefined,
    :undefined, :undefined}}]]
** Reason for termination = 
** {{:badmatch, ""},
 [{:ssl_handshake, :dec_hello_extensions, 2,
   [file: 'ssl_handshake.erl', line: 1737]},
  {:ssl_handshake, :decode_handshake, 3,
   [file: 'ssl_handshake.erl', line: 926]},
  {:tls_handshake, :get_tls_handshake_aux, 3,
   [file: 'tls_handshake.erl', line: 155]},
  {:tls_connection, :next_state, 4, [file: 'tls_connection.erl', line: 433]},
  {:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 503]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 237]}]}


16:50:10.642 [error] GenServer #PID<0.226.0> terminating
Last message: {:send_req, {{:url, 'https://api.github.com', 'api.github.com', 443, :undefined, :undefined, '/', :https, :hostname}, [], :get, "", [], 5000}}
State: {:state, 'api.github.com', 443, :undefined, #Reference<0.0.0.1352>, false, :undefined, [], true, :undefined, false, [], {[], []}, :undefined, :idle, :undefined, "", 0, 0, [], :undefined, :undefined, :undefined, :undefined, false, :undefined, :undefined, "", :undefined, false, 188446, 0, :undefined}
** (exit) exited in: :gen_fsm.sync_send_all_state_event(#PID<0.227.0>, {:start, 5000}, :infinity)
    ** (EXIT) an exception was raised:
        ** (MatchError) no match of right hand side value: ""
            (ssl) ssl_handshake.erl:1737: :ssl_handshake.dec_hello_extensions/2
            (ssl) ssl_handshake.erl:926: :ssl_handshake.decode_handshake/3
            (ssl) tls_handshake.erl:155: :tls_handshake.get_tls_handshake_aux/3
            (ssl) tls_connection.erl:433: :tls_connection.next_state/4
            (stdlib) gen_fsm.erl:503: :gen_fsm.handle_msg/7
            (stdlib) proc_lib.erl:237: :proc_lib.init_p_do_apply/3

nil
iex(41)> 
4

2 に答える 2

9

謎が解けました。この質問を Elixir-lang グループに投稿しましたが、これは Erlang OTP 17.3 の既知のバグです。解決策は、パッチを適用するか、次のバージョンを待つか、OTP 17.1 にダウングレードすることです。

詳細はこちら: https://groups.google.com/forum/#!topic/elixir-lang-talk/xsAEzCfmRoQ

于 2014-09-29T07:27:18.253 に答える
1

Erlang 17.1 にダウングレードするか、GitHub から最新のリリース タグ「OTP-17.3.4」を使用します - https://github.com/erlang/otp/releases

GitHub から「OTP-17.3.4」リリース タグを使用することを選択した場合は、ソースをダウンロードして untar/unzip し./otp_build autoconfたら、通常のビルド手順 (./configure、make、make install) を実行する前に を実行します。

17.3.4 は内部リリースであるため、Erlang の公式サイトにはリリースがありません。[ソース: https://twitter.com/brucify/status/537240367239016448] . ただし、Erlang Solutions サイトには 17.3 rev2 というビルドがあることがわかります。

于 2014-11-30T11:23:31.460 に答える