UlionTse / translators

🌏🌍🌎Translators🌎🌍🌏 is a library that aims to bring free, multiple, enjoyable translations to individuals and students in Python. Translators是一个旨在用Python为个人和学生带来免费、多样、愉快翻译的库。
https://pypi.org/project/translators/
GNU General Public License v3.0
1.76k stars 194 forks source link

translators.baidu() IndexError: list index out of range #52

Closed anything4share closed 2 years ago

anything4share commented 3 years ago

表用百度翻译,出现索引错位的问题, 如,translators.baidu(‘apple’)

UlionTse commented 3 years ago

@qunosen Please offer more information, including runtime environment, translators version, python version, detail error message, etc.

anything4share commented 3 years ago

@UlionTse I use code as follows on Windows 10 (python3.6, translators :https://github.com/UlionTse/translators, V4.9.5)

######################################## import translators as ts #### print(ts.baidu(‘apple’))

ERROR: ######################################## Exception in thread Thread-3: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\ProgramData\Anaconda3\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 1063, in _readerthread buffer.append(fh.read()) UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 76: illegal multibyte sequence

Traceback (most recent call last): File "translators-master/test.py", line 11, in print(ts.baidu('apple')) File "translators-master\translators\apis.py", line 488, in baidu_api self.host_info = self.get_host_info(host_html, sign_html, query_text) File "translators-master\translators\apis.py", line 453, in get_host_info js_data = execjs.get().eval(js_txt) File "C:\ProgramData\Anaconda3\lib\site-packages\execjs_abstract_runtime.py", line 25, in eval return self.compile('', cwd=cwd).eval(source) File "C:\ProgramData\Anaconda3\lib\site-packages\execjs_abstract_runtime_context.py", line 27, in eval return self._eval(source) File "C:\ProgramData\Anaconda3\lib\site-packages\execjs_external_runtime.py", line 78, in eval return self.exec(code) File "C:\ProgramData\Anaconda3\lib\site-packages\execjs_abstract_runtimecontext.py", line 18, in exec return self.exec(source) File "C:\ProgramData\Anaconda3\lib\site-packages\execjs_external_runtime.py", line 87, in exec output = self._exec_with_pipe(source) File "C:\ProgramData\Anaconda3\lib\site-packages\execjs_external_runtime.py", line 103, in _exec_with_pipe stdoutdata, stderrdata = p.communicate(input=input) File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 843, in communicate stdout, stderr = self._communicate(input, endtime, timeout) File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 1113, in _communicate stdout = stdout[0] IndexError: list index out of range

Process finished with exit code 1

UlionTse commented 3 years ago

@qunosen print(translators.__version__)

anything4share commented 3 years ago

@qunosen print(translators.__version__)

v4.9.5 version

UlionTse commented 3 years ago

@qunosen attention UnicodeDecodeError: 'gbk' codec can't decode byte 0xad in position 76: illegal multibyte sequence, and remove threading in your code.

UlionTse commented 3 years ago

@qunosen Mine, but run in Mac. 截屏2021-10-14 下午5 08 25

vlasvlasvlas commented 2 years ago

still same issue imagen