googleapis / nodejs-vision

This repository is deprecated. All of its content and history has been moved to googleapis/google-cloud-node.
https://cloud.google.com/vision/
Apache License 2.0
495 stars 139 forks source link

Trouble with OCR #495

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hey! So I recently migrated to Amazon Lightsail to host a project. However, since I started with it, I get the following error when attempting to use Cloud Vision:


SyntaxError: Unexpected token p in JSON at position 93

at JSON.parse (<anonymous>)

at ReadStream.<anonymous> (/home/bitnami/.jenkins/workspace/[my project]/node_modules/google-auth-library/build/src/auth/googleauth.js:347:39)

at ReadStream.emit (events.js:208:15)

at endReadableNT (_stream_readable.js:1161:12)

at processTicksAndRejections (internal/process/task_queues.js:77:11)

Environment details

Steps to reproduce

  1. Attempt to run code using vision client
                const vision = require("@google-cloud/vision");
                const visionClient = new vision.ImageAnnotatorClient();
                const [result] = await visionClient.textDetection(
                  cresult.secure_url
                );
                const detections = result.textAnnotations;
                let ocrresult = detections[0].description;
  2. ??
bcoe commented 4 years ago

@futurGH where were you running @google-cloud/vision prior to this? In GCP environments credentials are detected automatically, in an AWS environment, you will need to create a service account for credentials and point to the path using the environment variable GOOGLE_APPLICATION_CREDENTIALS, see:

https://cloud.google.com/docs/authentication/getting-started

ghost commented 4 years ago

@futurGH where were you running @google-cloud/vision prior to this? In GCP environments credentials are detected automatically, in an AWS environment, you will need to create a service account for credentials and point to the path using the environment variable GOOGLE_APPLICATION_CREDENTIALS, see:

https://cloud.google.com/docs/authentication/getting-started

Ah, that makes sense. I was previously running it on Glitch.com. I have the env variable set.

I assumed the service account aspect would be different because Lightsail seemed to be a simplified version of other EC2 instances. I'll give that a go. Thanks!

bcoe commented 4 years ago

:+1: please feel free to reopen this issue if you continue bumping into issues, but I think you'll find setting the variable does the trick.