3

I'm using the Google Calendar API to fetch some events and I'm using a venv to house all the packages required, and I've run into a simple problem: google.auth.transport.requests can't function correctly, citing the requests package is not installed.

Code and error:


The problem can be observed using a single line of code:

from google.auth.transport.requests import Request

The following error is dumped to the console from google.auth.transport.requests (at the bottom of two tracebacks):

File "<string>", line 3, in raise_from
ImportError: The requests library is not installed, please install the requests package to use the requests transport.

Failed attempts


  1. Deleting and remaking the venv.
  2. Install modules with --no-cache-dir and --ignore-installed.

Information


  1. Executing import requests or from google.auth.transport.requests import Request from the console from env\Scripts\python works without problem.
  2. The same lines when put in a file temp.py when placed inside the following directories execute in the following manner:
    • AutoMate\: Safe
    • AutoMate\src\: Safe
    • AutoMate\src\sources\: Error
    • AutoMate\src\sources\temp\: Safe (sources\temp only made for debugging)
    • AutoMate\src\sources\util\: Safe.

Note: All tests here and below have been ran from AutoMate\ using env\Scripts\python and env\Scripts\pip.

  1. None of the google auth modules have been installed in the pip outside of the venv.

  2. The project structure is as follows:

AutoMate
|   temp.py
├───env
│   ├───Include
│   ├───Lib
│   └───Scripts
└───src
    │   AutoMate.pyw
    │
    └───sources
        │   calendar.py --> Problematic file
        │   whatsapp.py
        │   __init__.py
        │  
        └───util

  1. Output of env\Scripts\pip list:
Package                  Version
------------------------ ---------
cachetools               4.2.1
certifi                  2020.12.5
chardet                  4.0.0
google-api-core          1.26.1
google-api-python-client 2.0.2
google-auth              1.27.1
google-auth-httplib2     0.1.0
google-auth-oauthlib     0.4.3
googleapis-common-protos 1.53.0
httplib2                 0.19.0
idna                     2.10
oauthlib                 3.1.0
packaging                20.9
pip                      21.0.1
protobuf                 3.15.5
pyasn1                   0.4.8
pyasn1-modules           0.2.8
pyparsing                2.4.7
pytz                     2021.1
requests                 2.25.1
requests-oauthlib        1.3.0
rsa                      4.7.2
selenium                 3.141.0
setuptools               49.2.1
six                      1.15.0
uritemplate              3.0.1
urllib3                  1.26.3
ankurbohra04
  • 432
  • 5
  • 12

2 Answers2

3

Solution


Any file that uses google.auth.transport.requests must not have any file named exactly calendar.py** in the same directory as itself. Any* other filename works, even calendar.python and Calendar.py.

** On testing it seems like requests.py and datetime.py are also some invalid names, while math.py and time.py seem to work fine, maybe the invalid names are used internally? Need further knowledge.

Reason


It looks like some there's some internal interference to me, I'm hoping someone will respond with the reason to this problem as well.

ankurbohra04
  • 432
  • 5
  • 12
0

There is a try-except block within google.auth.transport.requests while importing requests package, which defaults to that error message even if the package was already installed. Code

Trying to import requests directly in REPL revealed that there was in issue with from collections import Mapping (I was using Python v3.10 at the time). As suggested here, downgrading my Python version and creating a new venv helped me with this problem.