Comments (8)
不好意思,典型的商用api接口并不是我能提供的,请付费购买。您不能调用的,我这边都能调用,建议您不要频繁调用,谢谢。
from translators.
这不是商业接口。通用,免费的。
我的错误提示是Baidu api路径错误。
在此之前,并没有使用过百度API。
包括之前Alibaba 和bing不能使用,我之前在自己服务器上练习python,第一次测试就出现错误,绝未进行任何频繁调用。
另外,如果说是版本问题,我卸载过,重新安装,并查看版本,确实是4.4.2无疑。
另,我在一台全新服务器安装后,bing和alibaba api报同样的错。
Traceback (most recent call last):
File "test.py", line 3, in <module>
result = ts.baidu(to_trans, 'zh', 'en')
File "/usr/local/lib/python3.7/dist-packages/translators/apis.py", line 54, in wrapper
r = func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/translators/apis.py", line 299, in baidu_api
r.raise_for_status()
File "/home/ubuntu/.local/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://fanyi.baidu.com/v2transapi
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module>
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module>
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module>
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module>
import apt
File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
Original exception was:
Traceback (most recent call last):
File "test.py", line 3, in <module>
result = ts.baidu(to_trans, 'zh', 'en')
File "/usr/local/lib/python3.7/dist-packages/translators/apis.py", line 54, in wrapper
r = func(*args, **kwargs)
File "/usr/local/lib/python3.7/dist-packages/translators/apis.py", line 299, in baidu_api
r.raise_for_status()
File "/home/ubuntu/.local/lib/python3.7/site-packages/requests/models.py", line 941, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://fanyi.baidu.com/v2transapi
from translators.
不好意思,典型的商用api接口并不是我能提供的,请付费购买。您不能调用的,我这边都能调用,建议您不要频繁调用,谢谢。
我在多台服务器测试均报错(均是首次测试)
另外,您有尝试过全新安装translators库后测试吗?我觉得是不是从pip安装才会出现这些情况?
谢谢!
from translators.
@DaPoHou 根据你提供的401报错信息,确认应该是你的服务器环境导致的。你可以在你的笔记本尝试。具体401情况,参考此博文。
from translators.
@DaPoHou 根据你提供的401报错信息,确认应该是你的服务器环境导致的。你可以在你的笔记本尝试。具体401情况,参考此博文。
非常感谢您的解答。你有尝试过重新安装库,并测试吗?
我在三台服务器上测试均是这样。
都是直接使用apt install从python 3.5升级到3.7.
并更新/user/bin/python3软连接。
from translators.
我在win10商店了装了Python3.8,确实是正常的。
我在Ubuntu上,卸载了python3/pip,重新安装,错误仍然存在。
from translators.
print(self.api_url, self.host_headers, form_data, proxies)
https://cn.bing.com/ttranslatev3?isVertical=1&&IG=3AA4A8BD3910450F8F86534592555ACA&IID=translator.5028.1 {'Referer': 'h
ttps://cn.bing.com/Translator', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gec
ko) Chrome/55.0.2883.87 Safari/537.36'} {'text': '仰天长啸,壮怀激烈。', 'fromLang': 'auto-detect', 'to': 'en'} None
print(r)
<Response [200]>
print(data)
None
from translators.
@DaPoHou 我上传模块库之前肯定是测试的,但一般不会在各个环境去测试,测试一般是测程序本身的代码问题,所以没有在Linux上进行测试。我解读一下就是说,我所有的接口都是对应各个浏览器网页版免费翻译的接口,就是你在网页上交互翻译的那个,所以401就是说某些网页版接口会知道你并没有在浏览器环境下去使用,类似反爬虫策略一样。
from translators.
Related Issues (20)
- [Feature]: Return the chosen language (handy when using 'auto') HOT 2
- [Bug]: "The `query_text` can't be empty!" in translate_html HOT 1
- [Bug]: workaround of consent.google.com doesn't work anymore HOT 11
- [Feature]: Translation services (eg Bing) easily rate limited HOT 1
- [Bug]: translator server - google: language map is empty so getting error "Unsupported from_language[ar] in []" HOT 24
- [Bug]: Python 3 doesn't like re with Positive Lookbehind ? HOT 2
- [Bug]: KeyError: 'data' when using baidu HOT 2
- [Bug]: "Using region <name> server backend." printed on stdout HOT 1
- [Feature]: Georgian language HOT 1
- [Bug]: translate_html strips whitespace HOT 1
- [Bug]: Misleading error message HOT 1
- [Bug]: iciba not working now HOT 2
- [Feature]: 统一所有翻译器的源语言代码和目标语言代码 HOT 2
- [Bug]: Unable to find server backend. HOT 1
- [Bug]: crash HOT 3
- [Bug]: The function baidu() has been not certified yet HOT 3
- [Bug]: 504 Server Error: Gateway Time-out for url: https://aidemo.youdao.com/trans HOT 2
- [Bug]: TypeError: 'NoneType' object is not subscriptable HOT 3
- [Bug]: 对省略号翻译的时候就会发生一些错误 HOT 5
- [Bug]: KeyError: 'target' HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from translators.