Async Google API client
Aiogoogle makes it possible to access most of Google's public APIs which include:
You can find the documentation here.
Issue: I've been executing a script to fetch all the objects from cloud storage. There are around a lot of objects present in the bucket. Observation: The script fetches half of the objects in around 1 hr and then raises the below-mentioned error. Traceback: Traceback (most recent call last): ``` "async for blob_page in blobs_full_request: File "~/aiogoogle/models.py", line 341, in _next_page_generator prev_res = await sess.send(next_req, full_res=True) File "~/aiogoogle/sessions/aiohttp_session.py", line 183, in send results = await schedule_tasks() File "~/aiogoogle/sessions/aiohttp_session.py", line 175, in schedule_tasks return await asyncio.gather(*tasks, return_exceptions=False) File "~/aiogoogle/sessions/aiohttp_session.py", line 157, in get_response response.raise_for_status() File "~/aiogoogle/models.py", line 453, in raise_for_status raise AuthError(msg=self.reason, req=self.req, res=self) aiogoogle.excs.AuthError:
Unauthorized
Content: {'code': 401, 'errors': [{'domain': 'global', 'location': 'Authorization', 'locationType': 'header', 'message': 'Invalid Credentials', 'reason': 'authError'}], 'message': 'Invalid Credentials'}
Request URL: https://storage.googleapis.com/storage/v1/b/.... ``` Question: Is there any other way to reset the access token present in the session_factory's send() method? or am I missing a step?
code snippet:
blobs_full_request = await google_client.as_service_account(
storage_client.objects.list(bucket=BUCKET),
full_res=True,
)
async for blob_page in blobs_full_request:
yield blob_page
Possible issue: When pagination starts, if there are more pages to go through, the package fails to look for the validity of the access_token.
Suggested implementation for #79. Tested and working.
Each Google API response has a E-tag attached to it, which is included in the JSON response. If you save the response along with this E-tag, you can later check if the content of the response that you previously saved has has changed or not on the server, by adding the "If-None-Match" HTTP header to the API call. If the content has not changed, the API server answers with the code "304 not modifed".
This is a simple way to keep data retrieved from the API up to date.
The code of the API call would look like this:
python
async with Aiogoogle(
api_key= "your-api-key"
) as aiogoogle:
api = await aiogoogle.discover("youtube", "v3")
# etag hardcoded for the example, but this is supposed to be retrieved from the database or similar:
etag = "vsu1KWWbOO-15Idit0GDZKgEFfo"
result = await aiogoogle.as_api_key(
api.videos.list(
headers={"If-None-Match": etag},
part="snippet,contentDetails,statistics",
id="YOUR_VIDEO_ID"
),
full_res=True
)
if result.status_code == 304:
print("Resource was not modified since last check")
Great work with the repository, just a small request to add support for end-to-end testing. Like other open-source projects out there, can we get the endpoint for the server from OS so that the developer can overwrite such environment variable at the time of end-to-end testing?
I can't really find anything in docs about the use of pipe_to. The only clarification I could find is this, where bytes get just printed out.
What buffer does it need? How do I use it? Can someone please clarify this for me.
Importing aiogoogle raises a DeprecationWarning
. Usually we don't see it because Python filters it out, however when running tests with pytest it does show up and kinda messes up the output.
It's not really a big deal but I just thought it was worth flagging. Otherwise the lib is great!
You can see it by running the following:
bash
$ python -Wd -c "import aiogoogle"
C:\Python39\lib\abc.py:85: DeprecationWarning: Inheritance class AiohttpSession from ClientSession is discouraged
cls = super().__new__(mcls, name, bases, namespace, **kwargs)
aiogoogle: 3.2.1 Python: 3.9.2 OS: Windows 10
For ref: https://github.com/omarryhan/aiogoogle/issues/81
@KonstantAnxiety
Now you're able to configure safe parameters for URL encoding of path parameters being passed because they differ from one API to the other.
@jignesh-crest
Revert a previous change/bug-fix where path parameters with forward slashes "/" were being URL encoded, when they shouldn't. Now the encoding of forward slashes is optional again.
to: @Phil305
Now checking if token is fresh before sending next pagination request
@neel004 !
to: @erangalon !
async google-auth google-authentication discovery-service google-api google-cloud python-asyncio