'Unable to connect to Huggingface from EC2 instance

I am running a python code in EC2 instance where I am loading a Huggingface model using the from_pretrained() method. I get the error

OSError: Couldn't reach server at 'https://s3.amazonaws.com/models.huggingface.co/bert/bert-base-uncased-config.json' to download pretrained model configuration file.

while trying to initialize the reader. To get over this, I downloaded the file manually and provided the local JSON path. That worked fine but then I see issues in loading the tokenizer too.

OSError: Couldn't reach server at '{}' to download vocabulary files.

I think my network settings of EC2 are not correct due to which I am unable to connect to external Huggingface repository.

I tried relaxing the inbound rules for EC2 to IP version|Type|Protocol|Port range|Destination=>IPv4|All|traffic|All|All|0.0.0.0/0 but even that doesn't help. The outbound rules are already IPv4|All|traffic|All|All|0.0.0.0/0.

I also tried creating an IAM role with policy AmazonS3ReadOnlyAccess and attached it to the EC2 instance but still getting the same error. Could someone point what needs to be done to solve this. Thanks.



Solution 1:[1]

Here is how i fixed this issue. i installed pyopenssl like this :

!pip install pyopenssl

then i restarted terminal and re-ran the code and it fixed the issue for me,thanks

Solution 2:[2]

might be your network is using proxy this might help

$ proxies = {"http": 'foo.bar:3128', addyourproxy:'foo.bar:4012'}
$ from transformers import pipeline
$ qt_ans = pipeline('question-answering')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mobassir Hossen
Solution 2 Deepak Gupta