awsdocs / aws-doc-sdk-examples

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.
Apache License 2.0
9.6k stars 5.64k forks source link

[Bug]: NoRegionError #5218

Closed KrishPatel13 closed 1 year ago

KrishPatel13 commented 1 year ago

Expected behavior

Running python comprehend_detect.py should print the data follwoing from https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/python/example_code/comprehend/comprehend_detect.py#L176

But in my case it gave the below mentioned error.

Actual behavior

$ AWS_DEFAULT_REGION=us-east-1; python comprehend_detect.py
----------------------------------------------------------------------------------------
Welcome to the Amazon Comprehend detection demo!
----------------------------------------------------------------------------------------
Traceback (most recent call last):
  File "P:\OpenAdapt AI - MLDS AI\cloned_repo\test_other\OpenAdapt\openadapt\research_redaction\comprehend_detect.py", line 218, in <module>
    usage_demo()
  File "P:\OpenAdapt AI - MLDS AI\cloned_repo\test_other\OpenAdapt\openadapt\research_redaction\comprehend_detect.py", line 170, in usage_demo
    comp_detect = ComprehendDetect(boto3.client('comprehend'))
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\boto3\__init__.py", line 92, in client
    return _get_default_session().client(*args, **kwargs)
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\boto3\session.py", line 299, in client
    return self._session.create_client(
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\session.py", line 997, in create_client
    client = client_creator.create_client(
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\client.py", line 159, in create_client
    client_args = self._get_client_args(
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\client.py", line 490, in _get_client_args
    return args_creator.get_client_args(
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\args.py", line 100, in get_client_args
    final_args = self.compute_client_args(
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\args.py", line 219, in compute_client_args
    endpoint_config = self._compute_endpoint_config(
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\args.py", line 368, in _compute_endpoint_config
    return self._resolve_endpoint(**resolve_endpoint_kwargs)
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\args.py", line 473, in _resolve_endpoint
    return endpoint_bridge.resolve(
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\client.py", line 595, in resolve
    resolved = self.endpoint_resolver.construct_endpoint(
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\regions.py", line 229, in construct_endpoint
    result = self._endpoint_for_partition(
  File "C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\lib\site-packages\botocore\regions.py", line 277, in _endpoint_for_partition
    raise NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.

I have also tried other workarounds mentioned here: https://stackoverflow.com/questions/40377662/boto3-client-noregionerror-you-must-specify-a-region-error-only-sometimes

But still I get the same error

Steps to reproduce

1. Downloaded https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/python/example_code/comprehend/detect_sample.txt and https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/python/example_code/comprehend/comprehend_detect.py
2. Pip installed all libraries mentioned in https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/python/example_code/comprehend/requirements.txt
3. Ran `python comprehend_detect.py`

Logs / stacktrace (if applicable)

$ poetry env info

Virtualenv
Python:         3.10.11
Implementation: CPython
Path:           C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10
Executable:     C:\Users\Krish Patel\AppData\Local\pypoetry\Cache\virtualenvs\openadapt-DSRh12US-py3.10\Scripts\python.exe
Valid:          True

System
Platform:   win32
OS:         nt
Python:     3.10.11
Path:       C:\Program Files\Python310
Executable: C:\Program Files\Python310\python.exe
$ pip list
Package                       Version      Editable project location
----------------------------- ------------ ----------------------------------------------------------  
aiohttp                       3.8.4
aiosignal                     1.3.1
alabaster                     0.7.13
alembic                       1.8.1
altgraph                      0.17.3
annotated-types               0.5.0
anonympy                      0.3.7
anyio                         3.7.0
ascii-magic                   2.3.0
astroid                       2.15.5
asttokens                     2.2.1
async-timeout                 4.0.2
atomicwrites                  1.4.1
attrs                         23.1.0
Babel                         2.12.1
backcall                      0.2.0
beautifulsoup4                4.9.1
bidict                        0.22.1
black                         23.3.0
blis                          0.7.9
bokeh                         2.4.3
boto3                         1.28.21
botocore                      1.31.21
bottle                        0.12.25
breadability                  0.1.20
cape-dataframes               0.3.1
catalogue                     2.0.8
certifi                       2023.5.7
cffi                          1.15.1
cfgv                          3.3.1
chardet                       5.1.0
charset-normalizer            3.1.0
click                         8.1.3
clipboard                     0.0.4
clr-loader                    0.2.5
colorama                      0.4.6
coloredlogs                   15.0.1
comtypes                      1.2.0
confection                    0.1.0
contourpy                     1.1.0
coverage                      7.2.7
cycler                        0.11.0
cymem                         2.0.7
decorator                     4.4.2
deepdiff                      6.3.0
defusedxml                    0.6.0
dictalchemy3                  1.0.0
dill                          0.3.6
distlib                       0.3.6
docopt                        0.6.2
docutils                      0.20.1
en-core-web-sm                3.6.0
en-core-web-trf               3.5.0
exceptiongroup                1.1.1
executing                     1.2.0
expose-text                   0.1.6
Faker                         19.2.0
fastapi                       0.98.0
fastapi-socketio              0.0.10
filelock                      3.12.2
fire                          0.4.0
flake8                        6.1.0
flatbuffers                   23.5.26
fonttools                     4.40.0
frozenlist                    1.3.3
fsspec                        2023.6.0
fuzzywuzzy                    0.18.0
greenlet                      2.0.2
h11                           0.14.0
httptools                     0.5.0
huggingface-hub               0.15.1
humanfriendly                 10.0
identify                      2.5.24
idna                          3.4
imageio                       2.31.1
imageio-ffmpeg                0.4.8
imagesize                     1.4.1
importlib-metadata            6.7.0
iniconfig                     2.0.0
ipdb                          0.13.11
ipython                       8.14.0
isort                         5.12.0
jedi                          0.18.2
Jinja2                        3.1.2
jmespath                      1.0.1
joblib                        1.3.1
jsonschema                    3.2.0
kiwisolver                    1.4.4
langcodes                     3.3.0
lazy-object-proxy             1.9.0
Levenshtein                   0.21.1
loguru                        0.6.0
lxml                          4.9.2
Mako                          1.2.4
markdown2                     2.4.9
MarkupSafe                    2.1.3
matplotlib                    3.6.2
matplotlib-inline             0.1.6
mccabe                        0.7.0
more-itertools                9.1.0
moviepy                       1.0.3
mpmath                        1.3.0
mss                           6.1.0
multidict                     6.0.4
murmurhash                    1.0.9
mypy-extensions               1.0.0
networkx                      3.1
nicegui                       1.2.16
nltk                          3.8.1
nodeenv                       1.8.0
numpy                         1.25.0
onnxruntime                   1.15.1
openadapt                     0.5.6        P:\OpenAdapt AI - MLDS AI\cloned_repo\test_other\OpenAdapt  
openai                        0.27.5
opencv-python                 4.8.0.74
ordered-set                   4.1.0
orjson                        3.9.1
packaging                     23.1
pandas                        2.0.0
parso                         0.8.3
pathspec                      0.11.1
pathy                         0.10.2
pdf2image                     1.16.3
pdfkit                        0.6.1
pdfrw                         0.4
pefile                        2023.2.7
phonenumbers                  8.13.15
pickleshare                   0.7.5
Pillow                        9.5.0
pip                           23.2.1
platformdirs                  3.8.0
plotly                        5.15.0
pluggy                        1.2.0
poppler-utils                 0.1.0
pre-commit                    3.3.3
preshed                       3.0.8
presidio-analyzer             2.2.32
presidio-anonymizer           2.2.32
presidio-image-redactor       0.0.46
proglog                       0.1.10
prompt-toolkit                3.0.38
protobuf                      4.23.3
proxy-tools                   0.1.0
pscript                       0.7.7
psutil                        5.9.5
pure-eval                     0.2.2
py                            1.11.0
pyclipper                     1.3.0.post4
pycodestyle                   2.11.0
pycountry                     22.3.5
pycparser                     2.21
pycryptodome                  3.18.0
pydantic                      1.7.4
pydantic_core                 2.3.0
pydicom                       2.4.1
pyflakes                      3.1.0
PyGetWindow                   0.0.4
Pygments                      2.15.1
pyinstaller                   5.13.0
pyinstaller-hooks-contrib     2023.4
pylint                        2.17.4
Pympler                       1.0.1
pynput                        1.7.6
pyparsing                     3.1.0
PyPDF2                        3.0.1
pyperclip                     1.8.2
pypng                         0.20220715.0
pyreadline3                   3.4.1
PyRect                        0.2.0
pyrsistent                    0.19.3
pytesseract                   0.3.7
pytest                        7.4.0
pytest-cov                    2.10.0
python-dateutil               2.8.2
python-dotenv                 1.0.0
python-engineio               4.4.1
python-Levenshtein            0.21.1
python-multipart              0.0.6
python-socketio               5.8.0
pythonnet                     3.0.1
pytz                          2023.3
pywebview                     4.2.2
pywin32                       306
pywin32-ctypes                0.2.2
pywinauto                     0.6.8
PyYAML                        6.0
rapidfuzz                     3.1.1
rapidocr-onnxruntime          1.2.3
regex                         2023.6.3
requests                      2.31.0
requests-file                 1.5.1
rfc3339                       6.2
s3transfer                    0.6.1
safetensors                   0.3.1
scikit-learn                  1.2.2
scipy                         1.9.3
segment-anything              1.0
setuptools                    68.0.0
setuptools-lint               0.6.0
shapely                       2.0.1
six                           1.16.0
smart-open                    6.3.0
sniffio                       1.3.0
snowballstemmer               2.2.0
soupsieve                     2.4.1
spacy                         3.5.4
spacy-alignments              0.9.0
spacy-legacy                  3.0.12
spacy-loggers                 1.0.4
spacy-transformers            1.2.5
Sphinx                        7.0.1
sphinxcontrib-applehelp       1.0.4
sphinxcontrib-devhelp         1.0.2
sphinxcontrib-htmlhelp        2.0.1
sphinxcontrib-jsmath          1.0.1
sphinxcontrib-qthelp          1.0.3
sphinxcontrib-serializinghtml 1.1.5
SQLAlchemy                    1.4.43
srsly                         2.4.6
stack-data                    0.6.2
starlette                     0.27.0
sumy                          0.11.0
sympy                         1.12
tenacity                      8.2.2
termcolor                     2.3.0
texttable                     1.6.7
thinc                         8.1.10
threadpoolctl                 3.1.0
tiktoken                      0.4.0
tldextract                    3.4.4
tokenizers                    0.13.3
toml                          0.10.2
tomli                         2.0.1
tomlkit                       0.11.8
torch                         2.0.1
torchvision                   0.15.2
tornado                       6.3.2
tqdm                          4.64.0
traitlets                     5.9.0
transformers                  4.29.2
typer                         0.9.0
typing_extensions             4.7.0
tzdata                        2023.3
urllib3                       1.26.16
uvicorn                       0.20.0
validators                    0.20.0
vbuild                        0.8.1
virtualenv                    20.23.1
wasabi                        1.1.2
watchfiles                    0.18.1
wcwidth                       0.2.6
websockets                    11.0.3
wheel                         0.40.0
win32-setctime                1.1.0
wkhtmltopdf                   0.2
wrapt                         1.15.0
yarl                          1.9.2
zipp                          3.15.0


### Which SDK were you using?

Python

### Which OS were you using?

Windows

### SDK version

3.10.11

### OS version

Windows 11
rlhagerm commented 1 year ago

Hi @KrishPatel13, this may be an issue with your AWS credentials - could you check your ~/.aws/config file and try adding a default region as indicated in the Boto3 documentation here?

rlhagerm commented 1 year ago

Closing this issue as unable to reproduce. If you are still having issues, please re-open with additional information.