Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #85280
| From | Steve Dower <Steve.Dower@microsoft.com> |
|---|---|
| Subject | RE: [Python-Dev] Azure event hub network access |
| Date | 2015-02-06 05:45 +0000 |
| References | <CAHc+NX3Qpum5sVbVepVecm_eSsv-eCW6gCKi+S+-fVUc8r2f8A@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.18501.1423201542.18130.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
This would be much better posted on the github page for the project. I don't have the URL handy, but if you search github for "Python Azure SDK" you'll find it.
Cheers,
Steve
Sent from my Windows Phone
________________________________
From: syed khalid<mailto:syedk@pacificloud.com>
Sent: 2/5/2015 21:27
To: python-dev@python.org<mailto:python-dev@python.org>
Cc: python-list@python.org<mailto:python-list@python.org>
Subject: [Python-Dev] Azure event hub network access
I am getting http error 404. I am able to access the site via telnet which eliminates network issues. Here is the code and subsequent errors
user/bin/python
import sys
import azure
import socket
from azure.servicebus import (
_service_bus_error_handler
)
from azure.servicebus.servicebusservice import (
ServiceBusService,
ServiceBusSASAuthentication
)
from azure.http import (
HTTPRequest,
HTTPError
)
from azure.http.httpclient import _HTTPClient
class EventHubClient(object):
def sendMessage(self,body,partition):
eventHubHost = "pac-ns.servicebus.windows.net<http://pac-ns.servicebus.windows.net>"
httpclient = _HTTPClient(service_instance=self)
sasKeyName = "pac-pl"
sasKeyValue = "IhkEepQPLfSy9jo6H2Yxxxxxxxxxxxxxxxxxxxx="
authentication = ServiceBusSASAuthentication(sasKeyName,sasKeyValue)
request = HTTPRequest()
request.method = "POST"
request.host = eventHubHost
request.protocol_override = "https"
# request.path = "/myhub/publishers/" + partition + "/messages?api-version=20
14-05"
request.body = body
request.headers.append(('Content-Type', 'application/atom+xml;type=entry;cha
rset=utf-8'))
authentication.sign_request(request, httpclient)
request.headers.append(('Content-Length', str(len(request.body))))
status = 0
try:
resp = httpclient.perform_request(request)
status = resp.status
except HTTPError as ex:
status = ex.status
return status
class EventDataParser(object):
def getMessage(self,payload,sensorId):
host = socket.gethostname()
body = "{ \"DeviceId\" : \"" + host + "\",\"SensorData\": [ "
msgs = payload.split(",")
first = True
for msg in msgs:
# print msg
sensorType = msg.split(":")[0]
sensorValue = msg.split(":")[1]
if first == True:
first = False
else:
body += ","
body += "{ \"SensorId\" : \"" + sensorId + "\", \"SensorType\" : \"" + sen
sorType + "\", \"SensorValue\" : " + sensorValue + " }"
body += "]}"
return body
hubClient = EventHubClient()
parser = EventDataParser()
hostname = socket.gethostname()
sensor = sys.argv[2]
body = parser.getMessage(sys.argv[1],sensor)
hubStatus = hubClient.sendMessage(body,hostname)
# return the HTTP status to the caller
print hubStatus
print hostname
print sensor
~/IOT/AZURE$ python send.py temperature:22,humidity:20 deviceid
404
ubuntu
deviceid
{ "DeviceId" : "ubuntu","SensorData": [ { "SensorId" : "deviceid", "SensorType" : "temperature", "SensorValue" : 22 },{ "SensorId" : "deviceid", "SensorType" : "humidity", "SensorValue" : 20 }]}
--
Syed Khalid
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: [Python-Dev] Azure event hub network access Steve Dower <Steve.Dower@microsoft.com> - 2015-02-06 05:45 +0000
csiph-web