Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Cloud vision api response fails - 503 failed to connect to all addresses; last error: UNAVAILABLE:

weedle
New Member

Hi, 

I have been trying to fetch text from pics using the vision api. My code :

def google_vision_ocr(image_path, type=1😞
    try:
        credentials = service_account.Credentials.from_service_account_file(
                    filename="vision-ocr-private-key.json",
                    scopes=["https://www.googleapis.com/auth/cloud-platform"])
        client = vision.ImageAnnotatorClient(credentials=credentials)
        with io.open(image_path, "rb") as f:
            byteImage = f.read()
        image = vision.Image(content=byteImage)
        if type == 2:
            response = client.text_detection(image=image)
            print('Method 2 was hit')
        else:
            response = client.document_text_detection(image=image)
        text = response.full_text_annotation.text
        return text
    except Exception as e:
        return str(e)
 
This works fine in my local machine(windows 10) but inside vm(hyper v - windows 10) it gives the following error : 
503 failed to connect to all addresses; last error: UNAVAILABLE: ipv6:%5B2404:6800:4002:814::200a%5D:443: Network is unreachable
 
This error is only when vm connects to my organization wifi. When the vm is logged in with mobile hotspot, it again works fine. (Outside vm organisation wifi works fine). Tried testing with google drive api which works fine for both networks(organisation wifi & mobile hotspot) inside and outside vm. Ipconfig shows no difference between both networks in vm. Below is the result:
 
(base) C:\Users\clefa>ipconfig

Windows IP Configuration

Ethernet adapter Ethernet:

Connection-specific DNS Suffix . : mshome.net
Link-local IPv6 Address . . . . . : fe80::692c:1deb:6f4b:1abd%14
IPv4 Address. . . . . . . . . . . : 172.31.52.103
Subnet Mask . . . . . . . . . . . : 255.255.240.0
Default Gateway . . . . . . . . . : 172.31.48.1

(base) C:\Users\clefa>ipconfig

Windows IP Configuration

Ethernet adapter Ethernet:

Connection-specific DNS Suffix . : mshome.net
Link-local IPv6 Address . . . . . : fe80::692c:1deb:6f4b:1abd%14
IPv4 Address. . . . . . . . . . . : 172.31.52.103
Subnet Mask . . . . . . . . . . . : 255.255.240.0
Default Gateway . . . . . . . . . : 172.31.48.1

Network properties view is also the same for both networks.

What can be the reason that the api is not accepting requests only when its from vm + organisation wifi? Rest all cases work fine. Drive api works fine for all cases. Both have been authenticated using service accounts. Is there any solution/ workaround?

1 1 729
1 REPLY 1

Give a try to update the libraries which are used in your code.