SSL Error IBM Watson personality-insights Python

隐身守侯 提交于 2019-12-11 17:24:12

问题


I am trying to use the IBM personality insights service inside a for loop.

def generateToken(username, password):
    r = requests.get("https://gateway.watsonplatform.net/authorization/api/v1/token?url=https://gateway.watsonplatform.net/personality-insights/api", auth=(username, password))
    if r.status_code == requests.codes.ok:
        return r.text

def personalityRequest(text, token):
    base_url='https://gateway.watsonplatform.net/personality-insights/api/v3/profile?version=2017-08-17&consumption_preferences=true&raw_scores=true'
    headers = {'X-Watson-Authorization-Token': token, 'Content-Type': 'text/plain'}
    r = requests.post(base_url, headers=headers, data={'body': text})
    return r.text

token = generateToken('#username', '#password')

for user in range(0,user_data.shape[0]):
    user_data["user_personality"][user] = personalityRequest(user_data["user_preferences"][user], token)

The user_data is a panda dataframe with around 80 observations and user_preferences is a column with the user text.

When I run the above code I get proper responses for around 30 to 40 users and then it gives me below error.

SSLError: ("bad handshake: Error([('SSL routines', 
'ssl3_get_server_certificate', 'certificate verify failed')],)",)

来源:https://stackoverflow.com/questions/45809208/ssl-error-ibm-watson-personality-insights-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!