0

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')],)",)
ndmeiri
  • 4,979
  • 12
  • 37
  • 45
Charan
  • 11
  • 3
  • Why not just use the Python SDK? https://github.com/watson-developer-cloud/python-sdk – Simon O'Doherty Aug 22 '17 at 05:08
  • Yes I have checked this as well, this also gives same SSLerror. I thought may be as we trigger request with the same username and password repeatedly, we get the SSLerror so therefore authenticated using token. Even this yields the same error. – Charan Aug 22 '17 at 06:21
  • @SimonO'Doherty, the problem with Charan is because he wants to use one loop for the request, and when he uses the loop, he did get the SSL error – Sayuri Mizuguchi Aug 22 '17 at 12:29
  • At a guess, it's a rate limit kicking in. – Simon O'Doherty Aug 22 '17 at 13:15
  • @Simon O'Doherty : Any specific rate limit for NLC and Personality-insights services. Because sometimes the SSLError is thrown after 30 requests, sometimes 40. Even below 10 requests also. – Charan Aug 25 '17 at 06:28
  • I wouldn't know offhand. That sort of question may be better to ask on [DWAnswers](https://developer.ibm.com/answers/index.html) or support ticket. – Simon O'Doherty Aug 27 '17 at 03:53
  • Thank you Simon. Posted the query on DWAnswers. – Charan Aug 28 '17 at 06:03

0 Answers0