Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

请问为什么翻译.txt和.pdf文件时会出现以下问题(建议了解一下百度翻译API,貌似每月前200万字免费) #1

Open
sbkk000 opened this issue Aug 4, 2018 · 2 comments
Assignees

Comments

@sbkk000
Copy link

sbkk000 commented Aug 4, 2018

TXT文件
Traceback (most recent call last):
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\Main.py", line 122, in
run()
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\Main.py", line 50, in run
translate_doc(doc)
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\Main.py", line 64, in translate_doc
translate.translate()
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\T_Txt.py", line 44, in translate
line = f.readline()
UnicodeDecodeError: 'gbk' codec can't decode byte 0xff in position 0: illegal multibyte sequence

PDF文件
Traceback (most recent call last):
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\Main.py", line 122, in
run()
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\Main.py", line 50, in run
translate_doc(doc)
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\Main.py", line 64, in translate_doc
translate.translate()
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\T_Pdf_PyPDF2.py", line 57, in translate
self.write(line + '\n')
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\T_Pdf_PyPDF2.py", line 127, in write
f.write(content)
UnicodeEncodeError: 'gbk' codec can't encode character '\u2122' in position 672: illegal multibyte sequence

docx也报错了  ̄□ ̄||

Traceback (most recent call last):
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 964, in send
self.connect()
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 936, in connect
(self.host,self.port), self.timeout, self.source_address)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 724, in create_connection
raise err
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 713, in create_connection
sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\Main.py", line 122, in
run()
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\Main.py", line 50, in run
translate_doc(doc)
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\Main.py", line 64, in translate_doc
translate.translate()
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\T_Docx.py", line 53, in translate
trans = baidu_translate(para.text)
File "D:\desktop\TranslateTool-master\src\TranslateTool\TranslateTool\TranslateFunc.py", line 67, in baidu_translate
baidu_response = urllib.request.urlopen(baidu_re)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1346, in http_open
return self.do_open(http.client.HTTPConnection, req)
File "C:\Users\cc\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>

@AnuoF AnuoF self-assigned this Aug 6, 2018
@AnuoF
Copy link
Owner

AnuoF commented Aug 6, 2018

我用我demo里面的测试文档txt/doc/pdf均可正常翻译,看您的错误情况,应该是解码错误,可否把您要翻译的文档发我测试下呢?谢谢 我的邮箱 [email protected] @sbkk000

@sbkk000
Copy link
Author

sbkk000 commented Aug 7, 2018

已通过邮件将附件和建议发给您,现在就是api返回翻译结果有时候出错,
怎么能够重试出错时候的那一段,并把重复几次还出错的计入log里面

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants