0

I am building a python project using Google Vision API and hosting it on PythonAnywhere. The code snippet of the part which uses the API the task is as follows:

import os,io
from urllib import response
from google.cloud import vision
from google.auth.transport import requests
os.environ['GOOGLE_APPLICATION_CREDENTIALS']=r'Token_Vision.json'
client=vision.ImageAnnotatorClient()

file_name='test.jpg'
with io.open(file_name,'rb') as image_file:
    cont=image_file.read()
image=vision.Image(content=cont)
response = client.web_detection(image=image)
web_detection=response.web_detection

print(web_detection)
print("Done")

The code runs exactly as it is supposed to on the first run. But on subsequent runs it never runs and gives the following error:

Traceback (most recent call last):
  File "/home/whatever/mysite/test.py", line 6, in <module>
    client=vision.ImageAnnotatorClient()
  File "/home/whatever/.local/lib/python3.10/site-packages/google/cloud/vision_v1/services/image_annotator/client.py", line 462, in __init__
    self._transport = Transport(
  File "/home/whatever/.local/lib/python3.10/site-packages/google/cloud/vision_v1/services/image_annotator/transports/grpc.py", line 167, in __init
__
    self._grpc_channel = type(self).create_channel(
  File "/home/whatever/.local/lib/python3.10/site-packages/google/cloud/vision_v1/services/image_annotator/transports/grpc.py", line 222, in create
_channel
    return grpc_helpers.create_channel(
  File "/home/whatever/.local/lib/python3.10/site-packages/google/api_core/grpc_helpers.py", line 311, in create_channel
    composite_credentials = _create_composite_credentials(
  File "/home/whatever/.local/lib/python3.10/site-packages/google/api_core/grpc_helpers.py", line 254, in _create_composite_credentials
    metadata_plugin = google.auth.transport.grpc.AuthMetadataPlugin(
AttributeError: module 'google.auth.transport' has no attribute 'grpc'

How should I stop this from happening ?

0 Answers0