Invalid input JSON, Invalid UTF-8 middle byte

Hi all,

Here is the response error that I am receiving:

{“status”:“error”,“message”:“Invalid input JSON on line 1, column 39: Invalid UTF-8 middle byte 0x6f”,“correlationId”:“e1c67327-1455-47a4-a525-ef136721f550”}

I copied the sample python API code for searching the contact objects. When I tried to run the same code in my Python file, it fails. It seems to work only with non-accented text strings, but strings with characters such as “ñ” and “Ê” cause it to fail. Am I missing something to make it work with accented characters?

Thank for the help!

Wayde

# Sample code from the Hubspot API pages
# Search Contacts

import requests

url = "https://api.hubapi.com/crm/v3/objects/contacts/search"

querystring = {"hapikey":"XXXXXXXXXXXXXXXXXXXXXXXX"}

payload = "{\"filterGroups\":[{\"filters\":[{\"value\":\"Baño\",\"propertyName\":\"firstname\",\"operator\":\"EQ\"}]}],\"sorts\":[\"string\"],\"query\":\"string\",\"properties\":[\"string\"],\"limit\":0,\"after\":0}"
headers = {
 'accept': "application/json",
 'content-type': "application/json"
 }

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)

Hi @wfong ,

Are you still struggling with this?

I found a similar post involving umlauts that @akaiser both asked and resolved that may be of value to you.

@akaiser , @dornan1 , do you have thoughts on this?

Thanks!

d

Thanks @dennisedson for pointing me in the right direction!

Using @akaiser’s solution worked so thanks to him too!

For future googlers… I had this same problem, it’s when your request isn’t encoded in UTF-8.

ps. if you’re using java, the default Charset depends on your JVM. On macOS it’s UTF-8 but on appengine for example, it’s US_ASCII. Therefore, don’t rely on default, always choose the encoding. eg:

new StringEntity("café", StandardCharsets.UTF_8)

Thank you for adding your solution here, @MBurns !