无法从Python调用Azure Service Bus

时间:2012-06-12 15:33:00

标签: python azure

尝试运行hello world示例将一些东西放在队列中,创建一个队列......任何时候我调用azure我都会收到错误。

以下是代码:

from azure.servicebus import *

bus_service = ServiceBusService(service_namespace='testtest', account_key='my_access_token', issuer='my_issuer')
bus_service.create_topic('mytopic')

这是我回来的错误:

$ /c/Python27/python pythontest.py
Traceback (most recent call last):
  File "pythontest.py", line 4, in <module>
    bus_service.create_topic('mytopic')
  File "c:\Python27\lib\site-packages\azure\servicebus\servicebusservice.py", line 1
42, in create_topic
    request.headers = _update_service_bus_header(request, self.account_key, self.iss
uer)
  File "c:\Python27\lib\site-packages\azure\servicebus\__init__.py", line 185, in _u
pdate_service_bus_header
    request.headers.append(('Authorization', _sign_service_bus_request(request, acco
unt_key, issuer)))
  File "c:\Python27\lib\site-packages\azure\servicebus\__init__.py", line 192, in _s
ign_service_bus_request
    return 'WRAP access_token="' + _get_token(request, account_key, issuer) + '"'
  File "c:\Python27\lib\site-packages\azure\servicebus\__init__.py", line 233, in _g
et_token
    connection.send(request_body)
  File "c:\Python27\lib\site-packages\azure\http\winhttp.py", line 313, in send
    self._httprequest.send(request_body)
  File "c:\Python27\lib\site-packages\azure\http\winhttp.py", line 198, in send
    ctypes.memmove(safearray.pvdata, request, len(request))
WindowsError: exception: access violation writing 0x0000000000000000

无论是在队列中放置内容还是创建队列,创建主题,向主题发送消息等,它总是给我同样的错误。

任何想法?

2 个答案:

答案 0 :(得分:0)

这是您使用的确切代码吗?至少account_key不对,它应该是base64格式

bus_service = ServiceBusService(service_namespace='testtest', account_key='my_access_token', issuer='my_issuer') 

答案 1 :(得分:0)

当使用64位Python时,这是azure库的问题。

使它工作的变化很小,所以我已经在这里列出了它们。该修复程序也将很快推送到github + pypi。

azure / http / winhttp.py 进行以下更改:

c_size_t 添加到导入语句

from ctypes import c_void_p, c_long, c_ulong, c_longlong, c_ulonglong, c_short, c_ushort, c_wchar_p, c_byte, c_size_t

CoInitialize(0)替换为

CoInitialize(None)

Com相关API 部分替换为此

_ole32 = oledll.ole32
_oleaut32 = WinDLL('oleaut32')
_CLSIDFromString = _ole32.CLSIDFromString
_CoInitialize = _ole32.CoInitialize
_CoInitialize.argtypes = [c_void_p]

_CoCreateInstance = _ole32.CoCreateInstance

_SysAllocString = _oleaut32.SysAllocString
_SysAllocString.restype = c_void_p
_SysAllocString.argtypes = [c_wchar_p]

_SysFreeString = _oleaut32.SysFreeString
_SysFreeString.argtypes = [c_void_p]

_SafeArrayDestroy = _oleaut32.SafeArrayDestroy
_SafeArrayDestroy.argtypes = [c_void_p]

_CoTaskMemAlloc = _ole32.CoTaskMemAlloc
_CoTaskMemAlloc.restype = c_void_p
_CoTaskMemAlloc.argtypes = [c_size_t]