Я написал код для анализа каждого твита с помощью IBM Watson Tone Analyzer. Первоначально код работал и позволял анализировать каждый из 1000 твитов в списке в формате Json. Но теперь продолжает появляться ошибка подключения, в которой говорится:
SSLError: HTTPSConnectionPool(host='api.eu-gb.tone-analyzer.watson.cloud.ibm.com', port=443):
Max retries exceeded with url: /instances/148003f6-4092-49e6-bf71-2b48ffd0a55d/v3/tone?version=2017-09-21
(Caused by SSLError(SSLError("bad handshake: SysCallError(-1, 'Unexpected EOF')")))
Я не могу понять, что делать дальше. Пожалуйста помоги. (Примечание: я новичок в Python, пожалуйста, извините за неправильный код)
Мой код:
import json
from ibm_watson import ToneAnalyzerV3
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
authenticator = IAMAuthenticator('{API KEY}')
# I replaced with my API key above.
tone_analyzer = ToneAnalyzerV3(
version='2017-09-21',
authenticator=authenticator)
tone_analyzer.set_service_url('{URL}')
# I replaced with the actual URL above.
emotions_score3 = {}
for i in range(len(l3)):
text = l3[i]
tone_analysis = tone_analyzer.tone({'text': text},content_type='application/json').get_result()
tone=json.dumps(tone_analysis, indent=2)
jsonParse = json.loads(tone)
if "document_tone" in jsonParse.keys():
if jsonParse["document_tone"]["tones"]!=[]:
length = len(jsonParse["document_tone"]["tones"])
k = jsonParse["document_tone"]['tones']
for i in range(length):
n = k[i]['tone_name']
lockdown3.append(n)
if n in emotions_score3:
emotions_score3[n] = emotions_score3[n]+k[0]['score']
else:
emotions_score3.update({n:k[0]['score']})
else:
continue
else:
continue
Это формат Json pf результат, который я получил впервые, выглядит так:
{
"document_tone": {
"tones": [
{
"score": 0.73529,
"tone_id": "joy",
"tone_name": "Joy"
},
{
"score": 0.840028,
"tone_id": "tentative",
"tone_name": "Tentative"
}
]
},
"sentences_tone": [
{
"sentence_id": 0,
"text": "learn to live like hanuman jee, in this lock-down.",
"tones": [
{
"score": 0.724236,
"tone_id": "analytical",
"tone_name": "Analytical"
},
{
"score": 0.5538,
"tone_id": "tentative",
"tone_name": "Tentative"
}
]
}
]
}
"""