0

I'm trying to send the json data from azure ml to eventhub

import json
d = result.to_dict(orient='records')
data = json.dumps(d,ensure_ascii=False)

this is the screenshot of output of the variable data-output

import asyncio
from azure.eventhub.aio import EventHubProducerClient
from azure.eventhub import EventData
import time
conn_sting = "Endpoint=***"
async def run():
producer = EventHubProducerClient.from_connection_string(conn_str=conn_string)
async with producer:
    # Create a batch.
    event_data_batch = await producer.create_batch(partition_id='0')
    event_data_batch.add(EventData(data))

    # Send the batch of events to the event hub.
    await producer.send_batch(event_data_batch)
    
nest_asyncio.apply()
loop = asyncio.get_event_loop()
loop.run_until_complete(run())
print("sent to eventhub")

and getting following error..

Token authentication failed: 'utf-8' codec can't decode byte 0xe4 in 
position 0: invalid continuation byte
Token authentication failed: 'utf-8' codec can't decode byte 0xe4 in 
position 0: invalid continuation byte

anyone could help debug the error? thanks

1 Answers1

0

The exception is caused by the contents of your data dictionary, at least one of the keys or values is not UTF-8 encoded.

You can try with other encoding types like "ISO-8859-1" or "unicode_escape".

You can refer these SO threads for better understanding.

'utf8' codec can't decode byte 0xe4 ...: invalid continuation byte in timezone

"for line in..." results in UnicodeDecodeError: 'utf-8' codec can't decode byte

Utkarsh Pal
  • 4,079
  • 1
  • 5
  • 14