我是Python的超级初学者,我正在尝试做Coursera课程中的一个作业。我需要编写一个简单的代码,通过IBM沃森Translate连接并给予结果。到目前为止,根据说明,我已经创建了一个.env文件,其中包含Watson服务的apikey和url,然后我创建了另一个文件来翻译文本,如下所示:
import json
from ibm_watson import LanguageTranslatorV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
import os
from dotenv import load_dotenv
load_dotenv()
apikey = os.environ['apikey']
url = os.environ['url']
# Setup service
authenticator = IAMAuthenticator(apikey)
lt = LanguageTranslatorV3(version='2018-05-01', authenticator=authenticator)
lt.set_service_url(url)
translation = lt.translate(text='We are sinking.', model_id='en-de').get_result()
translation
translation['translations'][0]['translation']
此外,在测试代码之前,我已经运行了这些命令,以便按照指令加载库:
python3 -m pip install python-dotenv
python3 -m pip install ibm_watson
python3 -m pip install Flask
我遇到的错误是:
Traceback (most recent call last): File "translator.py", line 14, in <module>
lt = LanguageTranslatorV3(version='2018-05-01', authenticator=authenticator) File "/home/theia/.local/lib/python3.6/site-packages/ibm_watson/language_translator_v3.py", line 76, in __init__
authenticator=authenticator) File "/home/theia/.local/lib/python3.6/site-packages/ibm_cloud_sdk_core/base_service.py", line 97, in __init__
self.http_adapter = SSLHTTPAdapter() File "/home/theia/.local/lib/python3.6/site-packages/ibm_cloud_sdk_core/utils.py", line 35, in __init__
super().__init__(*args, **kwargs) File "/home/theia/.local/lib/python3.6/site-packages/requests/adapters.py", line 130, in __init__
self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block) File "/home/theia/.local/lib/python3.6/site-packages/ibm_cloud_sdk_core/utils.py", line 42, in init_poolmanager
ssl_context.minimum_version = ssl.TLSVersion.TLSv1_2 AttributeError: module 'ssl' has no attribute 'TLSVersion'
1条答案
按热度按时间wwtsj6pe1#
这个错误是因为你至少需要Python 3.7。
这是一个嵌套的依赖关系问题。即使
ibm-watson
6.1.0有Python 3.5作为依赖关系,它也依赖于ibm_cloud_sdk_core
3.3.6。如果这是您下载的版本,那么您可能没问题,但我怀疑您有最新的3.16.0。ibm_cloud_sdk_core
至少依赖于Python 3.7。我猜在3.3.6和3.16.0
ibm_cloud_sdk_core
之间的某个地方引入了一个突破性的变化。您可以使用检查软件包版本
或
另一种方法是删除现有的
ibm-cloud-sdk-core
版本,并无论哪种方式,您都应该在https://github.com/watson-developer-cloud/python-sdk上提出问题