2013-04-04 201 views
0

我有一個python腳本運行,通過http發送數據給idigi。當我在我的Mac上運行腳本時,它工作正常,數據顯示在服務器上,但是從Raspberry Pi運行時,它無法訪問服務器。它們連接在同一個網絡中,所以我認爲它與Raspberry Pi有關。 訪問http端口是否被拒絕?我該如何檢查以及如何解決?我搜查瞭如何確保港口是開放的,但沒有走得很遠。不太確定發生了什麼事。有任何想法嗎?Raspberry Pi idigi http messaging

我沒有得到任何依賴性錯誤。我使用了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() 

回答

0

這似乎與這裏描述的問題:https://askubuntu.com/questions/116020/python-https-requests-urllib2-to-some-sites-fail-on-ubuntu-12-04-without-proxy

我跟一些帖子上的信息上面創建一個示例腳本,將使用安全連接投入/ WS /消息通過在Raspbian上強制使用TLS 1.0(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