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

conversion error for attached json input #214

Closed datjandra closed 7 years ago

datjandra commented 7 years ago

Attached JSON file could be added from Discovery Tooling but not from Python SDK. No error is reported from Python code below but document upload failed according to Discovery Tooling.

discovery.add_document(environment_id=environment_id,
                                collection_id=collection_id,
                                file_data=fileinfo,
                                mime_type='application/json')

Occurred during: Conversions

5/31/2017 1:31:39 pm EDT
Error while converting document. Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser) at [Source: org.apache.commons.io.input.CloseShieldInputStream@434987c8; line: 1, column: 2]

USRE046396-20170502.json.txt

ehdsouza commented 7 years ago

Hi,

Looks like the the syntax you are using is incorrect. Use the following which works:

with open(os.path.join(os.getcwd(), 'USRE046396-20170502.json')) as fileinfo:
  add_doc = discovery.add_document({environment_id}, {collection_id}, file_info=fileinfo)

This was the output:

{
  "status": "processing",
  "document_id": "5797db29-89d9-45b9-b38b-8106f635dafd"
}

Check out the documentation here: https://www.ibm.com/watson/developercloud/discovery/api/v1/?python#add-doc

germanattanasio commented 7 years ago

I'm closing this since it's not an bug