Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'subject:: [': 0.04; 'subsequent': 0.05; 'subject:Python': 0.06; 'parser': 0.07; 'skip:\\ 20': 0.07; 'socket': 0.07; 'sys': 0.07; 'steve': 0.09; 'caller': 0.09; 'ex:': 0.09; 'http': 0.09; 'msg': 0.09; 'resp': 0.09; 'skip:\\ 10': 0.09; 'try:': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'def': 0.12; 'posted': 0.15; 'windows': 0.15; '","': 0.16; '"python': 0.16; '404': 0.16; 'hostname': 0.16; 'httperror': 0.16; 'subject:Dev': 0.16; 'subject:access': 0.16; 'to:name:python-dev@python.org': 0.16; 'true:': 0.16; 'url:windows': 0.16; "skip:' 30": 0.19; 'subject:] ': 0.20; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'error': 0.23; 'cheers,': 0.24; 'cc:2**0': 0.24; 'skip:" 30': 0.26; 'skip:" 40': 0.26; 'skip:" 20': 0.27; 'skip:_ 20': 0.27; 'to:addr:python-dev': 0.27; 'header:In-Reply-To:1': 0.27; 'to:2**1': 0.27; 'host': 0.29; 'skip:p 30': 0.29; 'errors': 0.30; 'skip:g 30': 0.30; 'code': 0.31; 'getting': 0.31; '"': 0.31; 'class': 0.32; 'skip:& 30': 0.33; 'except': 0.35; 'skip:s 30': 0.35; 'but': 0.35; 'false': 0.36; 'ubuntu': 0.36; 'email addr:python.org': 0.37; 'skip:& 10': 0.38; 'skip:_ 30': 0.39; 'skip:& 20': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; 'skip:a 30': 0.61; 'first': 0.61; "you'll": 0.62; 'charset:windows-1256': 0.64; 'email name :python-list': 0.65; 'phone': 0.66; 'here': 0.66; 'skip:r 40': 0.68; 'skip:r 30': 0.69; '[python-dev]': 0.84; 'azure': 0.84; 'email name:python-dev': 0.84; 'httprequest,': 0.84; 'hub': 0.84; 'syed': 0.84; 'eliminates': 0.91 From: Steve Dower To: syed khalid , "python-dev@python.org" Subject: RE: [Python-Dev] Azure event hub network access Thread-Topic: [Python-Dev] Azure event hub network access Thread-Index: AQHQQc2SZXgSTFC6NUasF0d5Ov6HEZzjHKlf Date: Fri, 6 Feb 2015 05:45:37 +0000 References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [166.171.250.103] authentication-results: pacificloud.com; dkim=none (message not signed) header.d=none; x-microsoft-antispam: BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0735; x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB0735; x-forefront-prvs: 047999FF16 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(2900100001)(122556002)(106116001)(86612001)(76576001)(46102003)(2950100001)(92566002)(66066001)(40100003)(16601075003)(16236675004)(33656002)(19580395003)(19580405001)(2656002)(86362001)(15975445007)(50986999)(102836002)(74316001)(87936001)(19617315012)(62966003)(76176999)(77156002)(54356999); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB0735; H:DM2PR0301MB0734.namprd03.prod.outlook.com; FPR:; SPF:None; MLV:sfv; LANG:en; Content-Type: multipart/alternative; boundary="_000_DM2PR0301MB07342199859E34D9429CC070F5380DM2PR0301MB0734_" MIME-Version: 1.0 X-OriginatorOrg: microsoft.onmicrosoft.com X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Feb 2015 05:45:37.6833 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM2PR0301MB0735 Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 394 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1423201542 news.xs4all.nl 2923 [2001:888:2000:d::a6]:35247 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:85280 --_000_DM2PR0301MB07342199859E34D9429CC070F5380DM2PR0301MB0734_ Content-Type: text/plain; charset="windows-1256" Content-Transfer-Encoding: quoted-printable 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'l= l find it. Cheers, Steve Sent from my Windows Phone ________________________________ From: syed khalid Sent: =FD2/=FD5/=FD2015 21:27 To: python-dev@python.org Cc: 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 =3D "pac-ns.servicebus.windows.net" httpclient =3D _HTTPClient(service_instance=3Dself) sasKeyName =3D "pac-pl" sasKeyValue =3D "IhkEepQPLfSy9jo6H2Yxxxxxxxxxxxxxxxxxxxx=3D" authentication =3D ServiceBusSASAuthentication(sasKeyName,sasKeyValue) request =3D HTTPRequest() request.method =3D "POST" request.host =3D eventHubHost request.protocol_override =3D "https" # request.path =3D "/myhub/publishers/" + partition + "/messages?api-ver= sion=3D20 14-05" request.body =3D body request.headers.append(('Content-Type', 'application/atom+xml;type=3Den= try;cha rset=3Dutf-8')) authentication.sign_request(request, httpclient) request.headers.append(('Content-Length', str(len(request.body)))) status =3D 0 try: resp =3D httpclient.perform_request(request) status =3D resp.status except HTTPError as ex: status =3D ex.status return status class EventDataParser(object): def getMessage(self,payload,sensorId): host =3D socket.gethostname() body =3D "{ \"DeviceId\" : \"" + host + "\",\"SensorData\": [ " msgs =3D payload.split(",") first =3D True for msg in msgs: # print msg sensorType =3D msg.split(":")[0] sensorValue =3D msg.split(":")[1] if first =3D=3D True: first =3D False else: body +=3D "," body +=3D "{ \"SensorId\" : \"" + sensorId + "\", \"SensorType\" : \"= " + sen sorType + "\", \"SensorValue\" : " + sensorValue + " }" body +=3D "]}" return body hubClient =3D EventHubClient() parser =3D EventDataParser() hostname =3D socket.gethostname() sensor =3D sys.argv[2] body =3D parser.getMessage(sys.argv[1],sensor) hubStatus =3D 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", "SensorT= ype" : "temperature", "SensorValue" : 22 },{ "SensorId" : "deviceid", "Sens= orType" : "humidity", "SensorValue" : 20 }]} -- Syed Khalid --_000_DM2PR0301MB07342199859E34D9429CC070F5380DM2PR0301MB0734_ Content-Type: text/html; charset="windows-1256" Content-Transfer-Encoding: quoted-printable
This would be= much better posted on the github page for the project. I don't have the UR= L handy, but if you search github for "Python Azure SDK" you'll f= ind it.

Cheers,
Steve

Sent from my Windows Phone

From: syed khalid
Sent: =FD2/= =FD5/=FD2015 21:27
To: python-dev@python.org
Cc: python-list@python.org
Subject: [Pyth= on-Dev] Azure event hub network access

I am getting http error 404. I am able to acces= s 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 =3D "pac-ns.servicebus.windows.net&qu= ot;

    httpclient =3D _HTTPClient(servic= e_instance=3Dself)

    sasKeyName =3D "pac-pl"=
    sasKeyValue =3D "IhkEepQPLfS= y9jo6H2Yxxxxxxxxxxxxxxxxxxxx=3D"

    authentication =3D ServiceBusSASA= uthentication(sasKeyName,sasKeyValue)

    request =3D HTTPRequest()<= /font>
    request.method =3D "POST&quo= t;
    request.host =3D eventHubHost
    request.protocol_override =3D &qu= ot;https"
#    request.path =3D "/myhub/pu= blishers/" + partition + "/messages?api-version=3D20
14-05"
    request.body =3D body
    request.headers.append(('Content-= Type', 'application/atom+xml;type=3Dentry;cha
rset=3Dutf-8'))

    authentication.sign_request(reque= st, httpclient)

    request.headers.append(('Content-= Length', str(len(request.body))))
status =3D 0

    try:
        resp =3D httpclient= .perform_request(request)
        status =3D resp.sta= tus
    except HTTPError as ex:
        status =3D ex.statu= s

    return status

class EventDataParser(object):

  def getMessage(self,payload,sensorId):
    host =3D socket.gethostname()
    body =3D "{ \"DeviceId\= " : \"" + host + "\",\"SensorData\&qu= ot;: [ "

    msgs =3D payload.split(",&qu= ot;)
    first =3D True

    for msg in msgs:
    # print msg
      sensorType =3D msg.split(&= quot;:")[0]
sensorValue =3D msg.split(":")[1]
      if first =3D=3D True:
        first =3D False
      else:
        body +=3D "= ;,"

      body +=3D "{ \&qu= ot;SensorId\" : \"" + sensorId + "\", \&qu= ot;SensorType\" : \"" + sen
sorType + "\", \"SensorValue= \" : " + sensorValue + " }"
    body +=3D "]}"

    return body

hubClient =3D EventHubClient()
parser =3D EventDataParser()
hostname =3D socket.gethostname()=
sensor =3D sys.argv[2]

body =3D parser.getMessage(sys.argv[1],sensor)<= /span>
hubStatus =3D hubClient.sendMessage(body,hostna= me)
# return the HTTP status to the caller
print hubStatus
print hostname
print sensor




~/IOT/AZURE$ python send.py temperature:22,humi= dity:20 deviceid 

404
ubuntu
deviceid
{ "DeviceId" : "ubuntu",&qu= ot;SensorData": [ { "SensorId" : "deviceid", "= ;SensorType" : "temperature", "SensorValue" : 22 }= ,{ "SensorId" : "deviceid", "SensorType" : &q= uot;humidity", "SensorValue" : 20 }]}




--
Syed Khalid

--_000_DM2PR0301MB07342199859E34D9429CC070F5380DM2PR0301MB0734_--