Python と v2 API を介してヒップチャット ルームに投稿しようとしています。
シェル スクリプトで curl を使用して問題なく投稿できます。
ROOM_ID=123
AUTH_TOKEN=123456789
MESSAGE="Hello World"
curl -H "Content-Type: application/json" \
-X POST \
-d "{ \"from\": \"GTM\",
\"notify\": \"true\",
\"color\": \"red\",
\"message_format\": \"text\",
\"message\": \"$MESSAGE\"
}" \
https://hipchat.server.domain.com/v2/room/$ROOM_ID/notification?auth_token=$AUTH_TOKEN
ただし、Python 経由で同じペイロードのメッセージを送信すると失敗します。私は既製のクライアントと、さまざまなhttpモジュールを介した単純なリクエスト、および次のような例を使用しました: https://gist.github.com/bdclark/4bc8ed06643e077fa620 (もちろん、SO自体を検索し、このような例をテストしました) .
基本的な例として、私はこれを試しました:
host = 'hipchat.host.domain.com'
room = '123'
message = "Hello World"
headers = {'Content-type: application/json'}
color = "yellow"
format = "text"
notify=False
AUTH_TOKEN="123456789"
url = "https://{0}/v2/room/{1}/notification?auth_token={2}".format(host, room, AUTH_TOKEN)
h = httplib2.Http()
payload = {
'from':'FROM',
'message': message,
'notify': notify,
'message_format': format,
'color': color
}
resp, content = h.request(url,"POST",urllib.urlencode(payload),headers=headers)
httplib2 (およびそれに基づくクライアント) はresponseNotReady
エラーを返します。リクエスト(およびそれに基づくクライアント) はConnection reset by peer
エラーを返します。
Curl は問題なく送信するため、おそらく Hipchat 自体の問題ではありません。Python のインストールに問題があるのではないかと思います (これは MacOs Sierra のデフォルトの 2.7 です)。したがって、問題は、エラーの根本的な原因をどのように見つけるかということです。
どんな助けでも大歓迎です。