googleapis / python-recommendations-ai

This library has moved to https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-recommendations-ai
Apache License 2.0
18 stars 9 forks source link

cant import catalog #20

Closed AhmadManzoor closed 3 years ago

AhmadManzoor commented 3 years ago

i am trying to import my catalog ( which i uploaded to bucket as json format) but it gives error {"code":3,"message":"Parsing terminated before end of input.

i copied the data from sample json as given here but the error is same. here is my json which i copied from reference website { "id": "1234", "category_hierarchies": [ { "categories": [ "athletic wear", "shoes" ] } ], "title": "ABC sneakers" }} { "id": "5839", "category_hierarchies": [ { "categories": [ "casual attire", "t-shirts" ] } ], "title": "Crew t-shirt" }} and here is the error

{"code":3,"message":"Parsing terminated before end of input.\n: \"ABC sneakers\" }}\n ^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":1}}]} {"code":3,"message":"Parsing terminated before end of input.\n: \"Crew t-shirt\" }}\n ^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":2}}]}

i will really appreciate any help

busunkim96 commented 3 years ago

Hi @AhmadManzoor,

It looks like Protobuf raises that error if the JSON has errors. https://github.com/protocolbuffers/protobuf/blob/a530dbe50c8295bf7b19e245b9be8525e235e6cb/src/google/protobuf/util/internal/json_stream_parser.cc#L221-L232

// Parse the remainder in finishing mode, which reports errors for things like // unterminated strings or unknown tokens that would normally be retried.

Can you double-check that the JSON is exactly as you've shown in your post?

{"id": "1234", "category_hierarchies": [ { "categories": [ "athletic wear", "shoes" ]  } ], "title": "ABC sneakers"}}
{"id": "5839","category_hierarchies": [ { "categories": [ "casual attire", "t-shirts" ]  } ], "title": "Crew t-shirt"}}

Could you also share the code you are using to import the catalog?

AhmadManzoor commented 3 years ago

thank you so much @busunkim96 for your quick response actually i am uploading the catalog online. i.e using gcp console and then selecting data and then clicking import ant then selecting json file in bucket. and i have copied the code from the website and i am using exact same json. Logically you are right and so is error as json is not valid. thats the problem i wanted to report that maybe online documentation has incorrect json example.

busunkim96 commented 3 years ago

Ah I see. Thank you for the clarification. I've opened an issue on that documentation page. I'll let you know once I hear back from the Recommendations AI team.

Googlers see 179488637.

AhmadManzoor commented 3 years ago

So any suggestion how can i upload the catalog now? as i have deadline in few days.

busunkim96 commented 3 years ago

Apologies, I'm not familiar with this product so I won't be able to offer further assistance until I hear back from the API team. If you have a support contract with Google, please do file a ticket https://cloud.google.com/support.

AhmadManzoor commented 3 years ago

Now i tried with valid json. i cheked it via jsonlint.com { "id": "WAG127836FN", "title": "Quasars IV", "categoryHierarchies": "" }, { "id": "WAG127833FN", "title": "Quasars I", "categoryHierarchies": "" }]

but still it is giving this error

{"code":3,"message":"Unexpected end of string. Expected a value or ] within an array.\n\n^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":1}}]} {"code":3,"message":"Unexpected end of string. Expected an object key or }.\n\n^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":2}}]} {"code":3,"message":"Parsing terminated before end of input.\n \"id\": \"WAG127836FN\",\n ^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":3}}]} {"code":3,"message":"Parsing terminated before end of input.\n \"title\": \"Quasars IV\",\n ^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":4}}]} {"code":3,"message":"Parsing terminated before end of input.\ncategoryHierarchies\": \"\"\n ^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":5}}]} {"code":3,"message":"Unexpected token.\n},\n^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":6}}]} {"code":3,"message":"Unexpected end of string. Expected an object key or }.\n\n^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":7}}]} {"code":3,"message":"Parsing terminated before end of input.\n \"id\": \"WAG127833FN\",\n ^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":8}}]} {"code":3,"message":"Parsing terminated before end of input.\n \"title\": \"Quasars I\",\n ^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":9}}]} {"code":3,"message":"Parsing terminated before end of input.\ncategoryHierarchies\": \"\"\n ^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":10}}]} {"code":3,"message":"Unexpected token.\n},\n^","details":[{"@type":"type.googleapis.com/google.protobuf.Struct","value":{"line_number":11}}]}

parthea commented 3 years ago

Hi @AhmadManzoor ,

As a test, could you try changing from

{ "id": "1234", "category_hierarchies": [ { "categories": [ "athletic wear", "shoes" ] } ], "title": "ABC sneakers" }}
{ "id": "5839", "category_hierarchies": [ { "categories": [ "casual attire", "t-shirts" ] } ], "title": "Crew t-shirt" }}

to

{ "id": "1234", "categories": "Apparel & Accessories > Shoes", "title": "ABC sneakers" }}
{ "id": "5839", "categories": "casual attire > t-shirts", "title": "Crew t-shirt" }}
parthea commented 3 years ago

Closed via #22