Giter Club home page Giter Club logo

Comments (8)

UlionTse avatar UlionTse commented on May 22, 2024

不好意思,典型的商用api接口并不是我能提供的,请付费购买。您不能调用的,我这边都能调用,建议您不要频繁调用,谢谢。
屏幕快照 2020-04-01 下午1 43 08

from translators.

DaPoHou avatar DaPoHou commented on May 22, 2024

这不是商业接口。通用,免费的。
我的错误提示是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.

DaPoHou avatar DaPoHou commented on May 22, 2024

不好意思,典型的商用api接口并不是我能提供的,请付费购买。您不能调用的,我这边都能调用,建议您不要频繁调用,谢谢。
屏幕快照 2020-04-01 下午1 43 08
我在多台服务器测试均报错(均是首次测试)
另外,您有尝试过全新安装translators库后测试吗?我觉得是不是从pip安装才会出现这些情况?
谢谢!

from translators.

UlionTse avatar UlionTse commented on May 22, 2024

@DaPoHou 根据你提供的401报错信息,确认应该是你的服务器环境导致的。你可以在你的笔记本尝试。具体401情况,参考此博文

from translators.

DaPoHou avatar DaPoHou commented on May 22, 2024

@DaPoHou 根据你提供的401报错信息,确认应该是你的服务器环境导致的。你可以在你的笔记本尝试。具体401情况,参考此博文

非常感谢您的解答。你有尝试过重新安装库,并测试吗?
我在三台服务器上测试均是这样。
都是直接使用apt install从python 3.5升级到3.7.
并更新/user/bin/python3软连接。

from translators.

DaPoHou avatar DaPoHou commented on May 22, 2024

我在win10商店了装了Python3.8,确实是正常的。
我在Ubuntu上,卸载了python3/pip,重新安装,错误仍然存在。

from translators.

DaPoHou avatar DaPoHou commented on May 22, 2024

debug

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.

UlionTse avatar UlionTse commented on May 22, 2024

@DaPoHou 我上传模块库之前肯定是测试的,但一般不会在各个环境去测试,测试一般是测程序本身的代码问题,所以没有在Linux上进行测试。我解读一下就是说,我所有的接口都是对应各个浏览器网页版免费翻译的接口,就是你在网页上交互翻译的那个,所以401就是说某些网页版接口会知道你并没有在浏览器环境下去使用,类似反爬虫策略一样。

from translators.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.