2017-09-15 66 views
0

我試圖從西班牙2個大文件,此代碼翻譯成英文: 進口goslategoslate從西班牙語翻譯成英文HTTP錯誤

big_files = ['lenin.txt', 'liga.txt'] 
gs = goslate.Goslate() 

translation = [] 
for big_file in big_files: 
    with open(big_file, 'r') as f: 
     translated_lines = [] 
     for line in f: 
      translated_line = gs.translate(line, "en") 
      translated_lines.append(translated_line) 

     translation.append('\n'.join(translated_lines)) 

我收到此錯誤:

File "C:\Anaconda\lib\urllib\request.py", line 590, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp)

HTTPError: Service Unavailable

回答

1

當通過Python訪問Web內容失敗時,通常適用的嘗試是通過瀏覽器訪問Web內容,以查看問題出在Python還是其他地方(如Internet連接)。無論你遇到什麼問題,另一個更普遍適用的策略是Google。第一款谷歌結果爲 「goslate」 返回此:

Google has updated its translation service recently with a ticket mechanism to prevent simple crawler program like goslate from accessing.

https://pypi.python.org/pypi/goslate

我認爲這解釋了你的問題。

+0

這是否意味着我必須將庫更改爲Google Cloud Translate? – anitasp

相關問題