Watson のLanguage Translatorを利用したいのですが、proxyエラーが出てしまいます。
どの部分で、プロキシ情報を適用すれば良いのでしょうか?
初歩的なことかと思いますが、なかなか情報が見つからず困っているので教えていただけると助かります。
Python
1import json 2from ibm_watson import LanguageTranslatorV3 3 4language_translator = LanguageTranslatorV3( 5 version='2018-05-01', 6 iam_apikey='{api_key}', 7 url='{url}') 8 9translation = language_translator.translate( 10 text='Hello', 11 model_id='en-es').get_result() 12print(json.dumps(translation, indent=2, ensure_ascii=False))
追記
情報が不足していましたので追記します。
ibm_watsonはAPIリファレンスを参考にpipで入手しました。
Python
1pip install --upgrade "ibm-watson>=3.4.0"
下記がエラーの全文になります。
Error
1During handling of the above exception, another exception occurred: 2 3ConnectionError Traceback (most recent call last) 4<ipython-input-19-40befa946038> in <module> 5 18 translation = language_translator.translate( 6 19 text='Hello', 7---> 20 model_id='en-es').get_result() 8 21 print(json.dumps(translation, indent=2, ensure_ascii=False)) 9 22 10 11c:\users\10001205180\python36\lib\site-packages\ibm_watson\language_translator_v3.py in translate(self, text, model_id, source, target, **kwargs) 12 178 params=params, 13 179 json=data, 14--> 180 accept_json=True) 15 181 return response 16 182 17 18c:\users\10001205180\python36\lib\site-packages\ibm_cloud_sdk_core\base_service.py in request(self, method, url, accept_json, headers, params, json, data, files, **kwargs) 19 367 auth = None 20 368 if self.token_manager: 21--> 369 access_token = self.token_manager.get_token() 22 370 headers['Authorization'] = '{0} {1}'.format(self.BEARER, access_token) 23 371 elif self.username and self.password: 24 25c:\users\10001205180\python36\lib\site-packages\ibm_cloud_sdk_core\jwt_token_manager.py in get_token(self) 26 54 return self.user_access_token 27 55 elif not self.token_info or self._is_token_expired(): 28---> 56 token_response = self.request_token() 29 57 self._save_token_info(token_response) 30 58 31 32c:\users\10001205180\python36\lib\site-packages\ibm_cloud_sdk_core\iam_token_manager.py in request_token(self) 33 58 headers=headers, 34 59 data=data, 35---> 60 auth_tuple=auth_tuple) 36 61 return response 37 62 38 39c:\users\10001205180\python36\lib\site-packages\ibm_cloud_sdk_core\jwt_token_manager.py in _request(self, method, url, headers, params, data, auth_tuple, **kwargs) 40 136 response = requests.request(method=method, url=url, 41 137 headers=headers, params=params, 42--> 138 data=data, auth=auth_tuple, **kwargs) 43 139 if 200 <= response.status_code <= 299: 44 140 return response.json() 45 46c:\users\10001205180\python36\lib\site-packages\requests\api.py in request(method, url, **kwargs) 47 58 # cases, and look like a memory leak in others. 48 59 with sessions.Session() as session: 49---> 60 return session.request(method=method, url=url, **kwargs) 50 61 51 62 52 53c:\users\10001205180\python36\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 54 531 } 55 532 send_kwargs.update(settings) 56--> 533 resp = self.send(prep, **send_kwargs) 57 534 58 535 return resp 59 60c:\users\10001205180\python36\lib\site-packages\requests\sessions.py in send(self, request, **kwargs) 61 644 62 645 # Send the request 63--> 646 r = adapter.send(request, **kwargs) 64 647 65 648 # Total elapsed time of the request (approximately) 66 67c:\users\10001205180\python36\lib\site-packages\requests\adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 68 514 raise SSLError(e, request=request) 69 515 70--> 516 raise ConnectionError(e, request=request) 71 517 72 518 except ClosedPoolError as e: 73 74ConnectionError: HTTPSConnectionPool(host='iam.cloud.ibm.com', port=443): Max retries exceeded with url: /identity/token (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000001F9A1A49320>: Failed to establish a new connection: [WinError 10060] 接続済みの呼び出し先が一定の時間を過ぎても正しく応答しなかったため、接続できませんでした。または接続済みのホストが応答しなかったため、確立された接続は失敗しました。',))
回答1件
あなたの回答
tips
プレビュー