Python Google translate error while translating text, ConnectionError:...












0















I want to convert bunch of sentences from Vietnamese to English saved in excel file. I have around 200 sentences. I have latest version of urllib3. Even if I keep just 10 sentences and run a code below I get following error. Is there any limit to number of sentences I can translate at a time?



Error:




ConnectionError: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))




Code:



from googletrans import Translator
import pandas as pd
import numpy as np
import time
import math
translator = Translator()

data=pd.read_excel('C:TextAnalyticsVietnamese to english.xlsx',dtype=object)


data.to_csv('data_temp.csv')

unique_data=pd.DataFrame(data['Subreason'].value_counts()).reset_index()[['index']]

unique_data['Translations']=''

for i in range(len(unique_data)):
temp=(unique_data['index'].iloc[i])
if(type(temp)==str):
print(temp)
a=translator.translate(temp,src='vi',dest='en')
unique_data['Translations'].iloc[i]=a.text
print(a.text)
if(i%20==0):
time.sleep(5)
print(i)
else:
time.sleep(1)

if(i>20000):
break

translate_dict=unique_data.set_index('index').to_dict().get('Translations')

data['Google_Translate']=data.REWORK_DESCRIPTION.map(translate_dict)

data.drop('Converted',inplace=True,axis=1)

path=r'data mv table.xls'
writer = pd.ExcelWriter(path, engine='openpyxl')
data.to_excel(writer, 'Translated', index=False)
writer.save()









share|improve this question























  • which library are you using? it doesn't seems the latest Translate API version. check this link: cloud.google.com/translate/docs/… And also this is the last API version: github.com/googleapis/google-cloud-python/tree/master/translate

    – Alex Riquelme
    Nov 21 '18 at 14:57











  • @AlexRiquelme: I am using googletrans. Is it mandatory to create billing account to use Google Translate API. I am new to this Google Translate API.

    – Aditi
    Nov 22 '18 at 8:21











  • Sorry, I can't help with that, I don't know anything about "googletrans"

    – Alex Riquelme
    Nov 22 '18 at 16:19
















0















I want to convert bunch of sentences from Vietnamese to English saved in excel file. I have around 200 sentences. I have latest version of urllib3. Even if I keep just 10 sentences and run a code below I get following error. Is there any limit to number of sentences I can translate at a time?



Error:




ConnectionError: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))




Code:



from googletrans import Translator
import pandas as pd
import numpy as np
import time
import math
translator = Translator()

data=pd.read_excel('C:TextAnalyticsVietnamese to english.xlsx',dtype=object)


data.to_csv('data_temp.csv')

unique_data=pd.DataFrame(data['Subreason'].value_counts()).reset_index()[['index']]

unique_data['Translations']=''

for i in range(len(unique_data)):
temp=(unique_data['index'].iloc[i])
if(type(temp)==str):
print(temp)
a=translator.translate(temp,src='vi',dest='en')
unique_data['Translations'].iloc[i]=a.text
print(a.text)
if(i%20==0):
time.sleep(5)
print(i)
else:
time.sleep(1)

if(i>20000):
break

translate_dict=unique_data.set_index('index').to_dict().get('Translations')

data['Google_Translate']=data.REWORK_DESCRIPTION.map(translate_dict)

data.drop('Converted',inplace=True,axis=1)

path=r'data mv table.xls'
writer = pd.ExcelWriter(path, engine='openpyxl')
data.to_excel(writer, 'Translated', index=False)
writer.save()









share|improve this question























  • which library are you using? it doesn't seems the latest Translate API version. check this link: cloud.google.com/translate/docs/… And also this is the last API version: github.com/googleapis/google-cloud-python/tree/master/translate

    – Alex Riquelme
    Nov 21 '18 at 14:57











  • @AlexRiquelme: I am using googletrans. Is it mandatory to create billing account to use Google Translate API. I am new to this Google Translate API.

    – Aditi
    Nov 22 '18 at 8:21











  • Sorry, I can't help with that, I don't know anything about "googletrans"

    – Alex Riquelme
    Nov 22 '18 at 16:19














0












0








0








I want to convert bunch of sentences from Vietnamese to English saved in excel file. I have around 200 sentences. I have latest version of urllib3. Even if I keep just 10 sentences and run a code below I get following error. Is there any limit to number of sentences I can translate at a time?



Error:




ConnectionError: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))




Code:



from googletrans import Translator
import pandas as pd
import numpy as np
import time
import math
translator = Translator()

data=pd.read_excel('C:TextAnalyticsVietnamese to english.xlsx',dtype=object)


data.to_csv('data_temp.csv')

unique_data=pd.DataFrame(data['Subreason'].value_counts()).reset_index()[['index']]

unique_data['Translations']=''

for i in range(len(unique_data)):
temp=(unique_data['index'].iloc[i])
if(type(temp)==str):
print(temp)
a=translator.translate(temp,src='vi',dest='en')
unique_data['Translations'].iloc[i]=a.text
print(a.text)
if(i%20==0):
time.sleep(5)
print(i)
else:
time.sleep(1)

if(i>20000):
break

translate_dict=unique_data.set_index('index').to_dict().get('Translations')

data['Google_Translate']=data.REWORK_DESCRIPTION.map(translate_dict)

data.drop('Converted',inplace=True,axis=1)

path=r'data mv table.xls'
writer = pd.ExcelWriter(path, engine='openpyxl')
data.to_excel(writer, 'Translated', index=False)
writer.save()









share|improve this question














I want to convert bunch of sentences from Vietnamese to English saved in excel file. I have around 200 sentences. I have latest version of urllib3. Even if I keep just 10 sentences and run a code below I get following error. Is there any limit to number of sentences I can translate at a time?



Error:




ConnectionError: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError(': Failed to establish a new connection: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond',))




Code:



from googletrans import Translator
import pandas as pd
import numpy as np
import time
import math
translator = Translator()

data=pd.read_excel('C:TextAnalyticsVietnamese to english.xlsx',dtype=object)


data.to_csv('data_temp.csv')

unique_data=pd.DataFrame(data['Subreason'].value_counts()).reset_index()[['index']]

unique_data['Translations']=''

for i in range(len(unique_data)):
temp=(unique_data['index'].iloc[i])
if(type(temp)==str):
print(temp)
a=translator.translate(temp,src='vi',dest='en')
unique_data['Translations'].iloc[i]=a.text
print(a.text)
if(i%20==0):
time.sleep(5)
print(i)
else:
time.sleep(1)

if(i>20000):
break

translate_dict=unique_data.set_index('index').to_dict().get('Translations')

data['Google_Translate']=data.REWORK_DESCRIPTION.map(translate_dict)

data.drop('Converted',inplace=True,axis=1)

path=r'data mv table.xls'
writer = pd.ExcelWriter(path, engine='openpyxl')
data.to_excel(writer, 'Translated', index=False)
writer.save()






python google-translate google-translation-api






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 5:33









AditiAditi

682721




682721













  • which library are you using? it doesn't seems the latest Translate API version. check this link: cloud.google.com/translate/docs/… And also this is the last API version: github.com/googleapis/google-cloud-python/tree/master/translate

    – Alex Riquelme
    Nov 21 '18 at 14:57











  • @AlexRiquelme: I am using googletrans. Is it mandatory to create billing account to use Google Translate API. I am new to this Google Translate API.

    – Aditi
    Nov 22 '18 at 8:21











  • Sorry, I can't help with that, I don't know anything about "googletrans"

    – Alex Riquelme
    Nov 22 '18 at 16:19



















  • which library are you using? it doesn't seems the latest Translate API version. check this link: cloud.google.com/translate/docs/… And also this is the last API version: github.com/googleapis/google-cloud-python/tree/master/translate

    – Alex Riquelme
    Nov 21 '18 at 14:57











  • @AlexRiquelme: I am using googletrans. Is it mandatory to create billing account to use Google Translate API. I am new to this Google Translate API.

    – Aditi
    Nov 22 '18 at 8:21











  • Sorry, I can't help with that, I don't know anything about "googletrans"

    – Alex Riquelme
    Nov 22 '18 at 16:19

















which library are you using? it doesn't seems the latest Translate API version. check this link: cloud.google.com/translate/docs/… And also this is the last API version: github.com/googleapis/google-cloud-python/tree/master/translate

– Alex Riquelme
Nov 21 '18 at 14:57





which library are you using? it doesn't seems the latest Translate API version. check this link: cloud.google.com/translate/docs/… And also this is the last API version: github.com/googleapis/google-cloud-python/tree/master/translate

– Alex Riquelme
Nov 21 '18 at 14:57













@AlexRiquelme: I am using googletrans. Is it mandatory to create billing account to use Google Translate API. I am new to this Google Translate API.

– Aditi
Nov 22 '18 at 8:21





@AlexRiquelme: I am using googletrans. Is it mandatory to create billing account to use Google Translate API. I am new to this Google Translate API.

– Aditi
Nov 22 '18 at 8:21













Sorry, I can't help with that, I don't know anything about "googletrans"

– Alex Riquelme
Nov 22 '18 at 16:19





Sorry, I can't help with that, I don't know anything about "googletrans"

– Alex Riquelme
Nov 22 '18 at 16:19












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405792%2fpython-google-translate-error-while-translating-text-connectionerror-httpsconn%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405792%2fpython-google-translate-error-while-translating-text-connectionerror-httpsconn%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

ComboBox Display Member on multiple fields

Is it possible to collect Nectar points via Trainline?