Пример #1
0
def postazq(postdata):
   # put your azure sb queue details here
   sbNamespace = 'nameSpace'
   sbEntityPath = 'EntityPath'
   sharedAccessKey = b'<your Azure key here>'
   sharedAccessKeyName = 'your Azure key name here'

   environment = 'https://yourname.servicebus.Windows.net'
   sessionUrl = urljoin(environment,'/yourname/messages')

   data = json.dumps(postdata).encode('utf-8')

   headers = {}
   headers['Content-type'] = "application/atom+xml;type=entry;charset=utf-8"
   headers['Authorization'] = sas.sas(sbNamespace,sbEntityPath,sharedAccessKey,sharedAccessKeyName)
   req = urllib.request.Request(sessionUrl, data, headers)
   try:
      response = urllib.request.urlopen(req, context=ctx)
      return response.status
   except HTTPError as httperror:
      return httperror.reason
   except URLError as urlerror:
      return urlerror.reason
Пример #2
0
from urllib.error import HTTPError
import sys
import sas

# put your azure sb queue details here
sbNamespace = 'chucks'
sbEntityPath = 'chucks'
sharedAccessKey = b'sharedAccessKey'
sharedAccessKeyName = 'chucks'

environment = 'https://chucks.servicebus.Windows.net'
sessionUrl = urljoin(environment, '/chucks/messages')

reqBody = {'temp': ''}
reqBody['temp'] = sys.argv[1]

data = json.dumps(reqBody).encode('utf-8')

headers = {}
headers['Content-type'] = "application/atom+xml;type=entry;charset=utf-8"
headers['Authorization'] = sas.sas(sbNamespace, sbEntityPath, sharedAccessKey,
                                   sharedAccessKeyName)
req = urllib.request.Request(sessionUrl, data, headers)
try:
    response = urllib.request.urlopen(req)
    print(response.status)
except HTTPError as httperror:
    print(httperror.reason)
except URLError as urlerror:
    print(urlerror.reason)
Пример #3
0
import urllib.request
from urllib.parse import urljoin
from urllib.error import URLError
from urllib.error import HTTPError
from datetime import datetime
import sas

sbNamespace = 'nameSpace'
sbEntityPath = 'EntityPath'
sharedAccessKey = b'<your Azure key here>'
sharedAccessKeyName = 'your Azure key name here'

environment = 'https://yourname.servicebus.Windows.net'
sessionUrl = urljoin(environment,'/yourname/messages/head')

headers = {}
headers['Authorization'] = sas.sas(sbNamespace,sbEntityPath,sharedAccessKey,sharedAccessKeyName)

req = urllib.request.Request(sessionUrl,headers=headers,method='DELETE')
response = urllib.request.urlopen(req)

if (response.status == 200):
  data = response.read()
  event = eval(data.decode('utf-8'))
  for key, value in event.items():
    print(key, datetime.fromtimestamp(value).strftime('%Y-%m-%d %H:%M:%S'))
else:
  print("Got status " + str(response.status))