0

我正在运行一个 python 脚本,它通过 http 向 idigi 发送数据。当我在我的 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 (2013-02-09) 上强制 TLS 1.0 使用安全连接来 PUT 到 /ws/Messaging:

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 回答