0

http経由でidigiにデータを送信するPythonスクリプトを実行しています。Mac でスクリプトを実行すると問題なく動作し、サーバーにデータが表示されますが、Raspberry Pi から実行するとサーバーにアクセスできません。それらは同じネットワークに接続されているので、Raspberry Pi に関係していると思います。http ポートへのアクセスが拒否されていませんか? 確認方法と修正方法を教えてください。ポートが開いていることを確認する方法を検索しましたが、あまりうまくいきませんでした。何が起こっているのかよくわかりません。何か案は?

依存関係エラーは発生しません。idigiが提案したのと同じコードを使用しました。http メッセージングを処理するコードのこの部分。

    # create HTTP basic authentication string, this consists of 
    # "username:password" base64 encoded 
    auth = base64.encodestring("%s:%s" % (username,password))[:-1]

    # Note, this is using Secure HTTP 
    webservice = httplib.HTTPS(idigi)


    # to what URL to send the request with a given HTTP method 
    webservice.putrequest("PUT", "/ws/Messaging/%s" % (filename))


    # add the authorization string into the HTTP header 
    webservice.putheader("Authorization", "Basic %s" % (auth)) 
    webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"") 
    webservice.putheader("Content-length", "%d" % len(body)) 
    webservice.endheaders()
    webservice.send(body)

    # get the response 
    statuscode, statusmessage, header = webservice.getreply() 
    response_body = webservice.getfile().read()
4

1 に答える 1

0

これは、ここで説明されている問題に関連しているようです: https://askubuntu.com/questions/116020/python-https-requests-urllib2-to-some-sites-fail-on-ubuntu-12-04-without-proxy

上記の投稿の情報の一部に従って、Raspbian で TLS 1.0 を強制することにより、安全な接続を使用して /ws/Messaging に PUT するサンプル スクリプトを作成しました (2013-02-09):

import base64
import httplib
import socket
import ssl

username = "00000000-00000000-00000000-00000000"
password = "password"
idigi = "my.idigi.com"
filename = "myfile"
body = "contents"

print "Encoding Credentials"
auth = base64.encodestring("%s:%s" % (username,password))[:-1]

print "Creating HTTPS instance"
conn = httplib.HTTPSConnection(idigi)
sock = socket.create_connection((conn.host, conn.port), conn.timeout, conn.source_address) 
conn.sock = ssl.wrap_socket(sock, conn.key_file, conn.cert_file, ssl_version=ssl.PROTOCOL_TLSv1) 
conn.request("PUT", "/ws/Messaging/%s" % filename, body, {"Authorization": "Basic %s" % (auth), "Content-length": "%d" % len(body)})

response = conn.getresponse()

print "HTTPS response is: %s" % response
于 2013-04-15T20:44:34.937 に答える