watson-developer-cloud / python-sdk

:snake: Client library to use the IBM Watson services in Python and available in pip as watson-developer-cloud
https://pypi.org/project/ibm-watson/
Apache License 2.0
1.46k stars 827 forks source link

Call to Tone analyzer with Json fails #319

Closed hande1 closed 6 years ago

hande1 commented 6 years ago

I'm trying to use tone_analyzer. When I send tweets one-by-one, it works well. If I send a huge json, I'm getting this error. I'd appreciate any help.

Traceback (most recent call last):
  File "tone_1201.py", line 33, in <module>
    tone = tone_analyzer.tone(json.load(jsonfile),content_type='application/json')
  File "/usr/local/lib/python2.7/dist-packages/watson_developer_cloud/tone_analyzer_v3.py", line 75, in tone
    json=text, accept_json=True)
  File "/usr/local/lib/python2.7/dist-packages/watson_developer_cloud/watson_developer_cloud_service.py", line 324, in request
    raise WatsonException(error_message)
watson_developer_cloud.watson_developer_cloud_service.WatsonException: Unknown error, Code: 500
germanattanasio commented 6 years ago

@hande1 which version of the SDK are you using?

ehdsouza commented 6 years ago

@hande1 you could also provide a snippet so that we could help you better.

hande1 commented 6 years ago

The version is : watson-developer-cloud==0.26.1

for fn in os.listdir(directory):
    if fn[len(fn)-4:len(fn)] == 'json':
        OutFile = directory +fn[0:len(fn)-4]+'_ans.json'
        with open(os.path.join(directory, fn), 'r') as jsonfile:
           tone = tone_analyzer.tone(json.load(jsonfile),content_type='application/json')
        print(json.dumps(tone, indent=1))
        write_json( tone, OutFile)

Thanks,

ehdsouza commented 6 years ago

Could you use the latest release and try? v1.0.1 is the latest

hande1 commented 6 years ago

After writing you, I realized it's not the current version, upgraded, still the same error.

Patataman commented 6 years ago

Stupid question: Are you sure you are sending a json file?

More likely problem: Inside the tone method documentation it says:

You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format

:param ToneInput tone_input: JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type ToneInput.

Maybe your problem is related with some of those 2 restrictions.

hande1 commented 6 years ago

yes, I dig the documentation for the file size restriction, couldn't find, but, I was almost sure because the connection is dead after some seconds. With 10 tweets in Json, it's working. I tried the system to work with 20000 tweets :) So, the aim was doing the sentimental analysis on the tweets that contain particular hashtags. I tried the same thing with real time twitter data (no hashtag filter) on IBM cloud and think it's better to use it on IBM cloud with spark and real time tweets.

Thanks to all of you,

Hande