我对python完全陌生。我正在尝试使用azure.servicebus模块。https://pypi.org/project/azure-servicebus/
我生成一行行json字符串,希望将其传递给servicebus。如果我有两行或两行以上,那就行了。如果我只有一行,它会将字符串中的每个字符拆分成行。
from ayx import Alteryx
from azure.servicebus import ServiceBusClient, ServiceBusMessage
import os
connstr = "xxxxx"
queue_name = "invoicedk"
df = Alteryx.read("#1")
print(df)
alteryxMessage = df.squeeze()
for specificationRows in alteryxMessage.items:
with ServiceBusClient.from_connection_string(connstr) as client:
with client.get_queue_sender(queue_name) as sender:
# Sending a single message
single_message = ServiceBusMessage(specificationRows)
sender.send_messages(single_message)
我从Alteryx得到的信息是:`
JSON
{"SpecificationNumber":"A120000010681","InvoiceGroup":"1000004597","FromCriteria":"2022-07-29","ToCriteria":"2022-09-29","SalesProductName":"Freight as per specification ZERO","Price":"52486.00","SpecificationDate":"2022-11-02","VATIdentity":"ZERO","CurrencyMDM":"EUR","NavisionInstance":"1000000001","SalesService":"","ServiceQuantity":"1","PricePrUnit":"52486.00","LengthRecordID":"1"}
{"SpecificationNumber":"A120000010682","InvoiceGroup":"1000004601","FromCriteria":"2022-06-07","ToCriteria":"2022-09-02","SalesProductName":"Freight as per specification ZERO","Price":"93282.59","SpecificationDate":"2022-11-02","VATIdentity":"ZERO","CurrencyMDM":"EUR","NavisionInstance":"1000000001","SalesService":"","ServiceQuantity":"1","PricePrUnit":"93282.59","LengthRecordID":"1"}
`
我尝试过计数项目,但如果只有1行,则会失败。所以不知道该怎么办。如果计数>1然后它就工作了。但是
s=df.scruze((打印(s.count(((
AttributeError: 'numpy.int64' object has no attribute 'count'
try:
for colname in df.columns:
try:
df[colname] = df[colname].astype('str')
print(f"{colname} converted")
except ValueError:
print(f"{colname} failed")