system.net.httpClient().get(url) is giving invalid url error for Google Translation API for Translating language from Tamil to English

Am getting Invalid URL at index 145 error in the below code. Basically, this code is accessing the Google Translate API to do the translation
Here is my code:
url = "https://translate.googleapis.com/translate_a/single?otf=1&hl=en-US&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&tsel=0&ssel=0&q=அனைத்தும்+திறந்திருக்கும்&oe=UTF-16&tk=xxxx&tl=en-US&client=gtx&sl=auto&ie=UTF-16"

response = system.net.httpClient().get(url)
response = client.get(url)
result = response.getText()
print response

You have international characters in a python conventional string constant. You need to mark the string constant as unicode, like so:

u"some string with unicode"
2 Likes

Also, you are creating an httpClient instance in every request. This will leak memory and produce many stale threads. Create one instance as a top-level variable in a project library script and use it for all of your requests.

1 Like