Question

Accent Marks/Special Characters in Python Request

  • 4 June 2021
  • 1 reply
  • 1500 views

Userlevel 1

Hello!

 

I’m using CODE by Zapier tu run a POST request in order to save contacts to my CRM platform.

The problem is that some contacts names or last names have special characters such as accent marks (á, é, í, ó, ú) or the letter “ñ”

I’m using Python Request to send the POST Request and adding the value to the JSON as shown below:

 

import http.client

conn = http.client.HTTPSConnection("api.icommarketing.com")
payload = "{\r\n \"ProfileKey\":\"[SECRET KEY]\", \r\n\"Contact\":\r\n{\"Email\":\""+input_data['email']+"\",\r\n \"CustomFields\":[\r\n{\"Key\":\"d_first_name\",\"Value\":\""+input_data['nombre']+"\"},\r\n{\"Key\":\"d_last_name\",\"Value\":\"Neiva\"},\r\n{\"Key\":\"d_celular\",\"Value\":\"Neiva\"},\r\n{\"Key\":\"q88696_ltbgtconoces_y_aceptas_la_poli\",\"Value\":\"Neiva\"}\r\n ]\r\n}\r\n}\r\n"
headers = {
'Authorization': '[SECRET KEY]',
'Content-Type': 'application/json',
'Cookie': 'ASP.NET_SessionId=4sbyadeh0bgrlimefr2abzpk'
}
conn.request("POST", "/Contacts/SaveContact.Json/", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

Everytime the action faces a special character or a “ñ” it generates error code. The example above returns error since the input field number is equal to “Lucás”, with the accent mark on the “a” letter.

Is there a way to include the variables in the JSON ignoring these special characters?

 

Thanks in advance

 

 


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

1 reply

Userlevel 4
Badge +9

Hey @LucasIcomm

Have you looked at the Formatter by Zapier/Convert to ASCII function? https://zapier.com/help/doc/how-get-started-formatter-zapier#other-text-transforms 

Otherwise, the best place to ask for help with your code is http://stackoverflow.com. Just tag your question with a “Zapier” tag and usually there will be folks who are willing to help you out. You can see all the questions that have already been asked here: https://stackoverflow.com/questions/tagged/zapier

If you haven’t already, definitely read through our documentation to make sure your code is following our guidelines and all your inputs and outputs are set correctly - though it sounds like you have a handle on that already 😀


https://zapier.com/help/code/#introduction

Additional Resources:

https://zapier.com/help/how-get-started-code-zapier/
https://zapier.com/help/how-get-started-code-python-zapier/
https://zapier.com/help/code-python-examples/https://zapier.com/help/code-examples/

 

Hope this helps!