omarryhan/aiogoogle

TypeError when requesting youtube.channels.list(part='statistics')

Closed this issue · 9 comments

here is my test code

async def create_api():
    async with Aiogoogle(api_key=my_api_key) as google:
        youtube = await google.discover('youtube', 'v3')
        result = await google.as_api_key(
            youtube.channels.list(
                part='snippet',
                id='UCwRKt_raV3N5KZgxcFyC1vw'
            )
        )
        print(result)
        result = await google.as_api_key(
            youtube.channels.list(
                part='statistics',
                id='UCwRKt_raV3N5KZgxcFyC1vw'
            )
        )
        print(result)

For the first request, I can get the result succesfully
While for the second one, I get the following information:

Traceback (most recent call last):
File "testt.py", line 24, in
create_api()
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\asyncio\runners.py", line 43, in run
return loop.run_until_complete(main)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\asyncio\base_events.py", line 584, in run_until_complete
return future.result()
File "testt.py", line 17, in create_api
id='UCwRKt_raV3N5KZgxcFyC1vw'
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\client.py", line 255, in as_api_key
return await self.active_session.send(*authorized_requests, timeout=timeout, full_res=full_res, session_factory=self.session_factory)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\sessions\aiohttp_session.py", line 153, in send
results = await schedule_tasks()
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\sessions\aiohttp_session.py", line 144, in schedule_tasks
return await asyncio.gather(tasks, return_exceptions=False)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\sessions\aiohttp_session.py", line 135, in get_content
response = await get_response(request)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\sessions\aiohttp_session.py", line 132, in get_response
response = _call_callback(request, response)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\sessions\common.py", line 5, in _call_callback
response.json = request.callback(response.content)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\resource.py", line 401, in
callback=lambda res: self._validate_response(res, validate)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\resource.py", line 505, in _validate_response
self.validate(res, response_schema, schema_name)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\resource.py", line 242, in validate
return validate
(instance, schema, self.schemas, schema_name)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 337, in validate
validate_object()
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 317, in validate_object
validate(instance[k], v, schemas, schema_name=k)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 341, in validate
validate_array()
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 324, in validate_array
validate(item, schema
, schemas, schema_name=schema_name)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 337, in validate
validate_object()
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 317, in validate_object
validate(instance[k], v, schemas, schema_name=k)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 337, in validate
validate_object()
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 317, in validate_object
validate(instance[k], v, schemas, schema_name=k)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 344, in validate
validate_all(instance, schema, schema_name)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 229, in validate_all
validate_format(instance, schema, schema_name)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 210, in validate_format
format_validator(instance, schema_name)
File "C:\Users\xybri\AppData\Local\Programs\Python\Python37\lib\site-packages\aiogoogle\validate.py", line 130, in uint64_validator
if (value > 9223372036854775807
2) or (value < 0):
TypeError: '>' not supported between instances of 'str' and 'int'

I did not find out why this error happened.

I will take a look at it. Meanwhile, you can turn off local validation and see if it works without it. e.g.

youtube.channels.list( part='statistics', id='UCwRKt_raV3N5KZgxcFyC1vw', validate=False )

You can also turn validation off globally by:

youtube = await aiogoogle.discover('youtube', 'v3', validate=False)

I think it will probably raise a 403 since you're using an API key for personal info. Let me know how it goes

I will take a look at it. Meanwhile, you can turn off local validation and see if it works without it. e.g.

youtube.channels.list( part='statistics', id='UCwRKt_raV3N5KZgxcFyC1vw', validate=False )

You can also turn validation off globally by:

youtube = await aiogoogle.discover('youtube', 'v3', validate=False)

I think it will probably raise a 403 since you're using an API key for personal info. Let me know how it goes

now it returns successfully if I turn off the validation

{'kind': 'youtube#channelListResponse', 'etag': '"XpPGQXPnxQJhLgs6enD_n8JR4Qk/q5nsmgGwx0zhnBbVz9zNZR9Rosw"', 'pageInfo': {'totalResults': 1, 'resultsPerPage': 1}, 'items': [{'kind': 'youtube#channel', 'etag': '"XpPGQXPnxQJhLgs6enD_n8JR4Qk/I5ksSOHLfenpIkGVx5QOeO9yyt8"', 'id': 'UCwRKt_raV3N5KZgxcFyC1vw', 'statistics': {'viewCount': '5574170', 'commentCount': '0', 'subscriberCount': '75217', 'hiddenSubscriberCount': False, 'videoCount': '55'}}]}

I thought it did get responses from the google server successfully because a few days ago I runned out of my api quota when I wrote something like:

while True:
    try:
        result =  await response
        break
    except:
        pass

I think the errors are being raised because some numbers are returned as strings instead of being float or int. I just pushed a fix, can you test it for me? :)

I replace the code in validate.py directly... Now it doesn't raise TypeError now.

Which part did you replace?

emmm.... I just found you update the code so I replace all..... The version before is 0.1.3

Does 0.1.4 fix the validation issues you initially had?

yes!