jsonapi-client icon indicating copy to clipboard operation
jsonapi-client copied to clipboard

Cant figure out how to use async

Open oefterdal opened this issue 2 years ago • 0 comments

from settings import Settings
from jsonapi_client import Session, Filter, ResourceTuple, Modifier, Inclusion


headers = {'headers': {
    'Accept': 'application/vnd.api+json',
    'Authorization': f"Bearer {Settings().access_token}"}}
async with Session(server_url="https://api.example.com/", request_kwargs=headers, enable_async=True) as s:
    querystring = 'filter[created_at][path]=created_at&filter[created_at][value]=2022-08-01 00:00:00...2022-09-01 00:00:00&filter[created_at][operator]=between'
    include = Inclusion("order-totals,order-status,order-products")
    modifier = Modifier("page[size]=10&page[number]=1")
    filter = Filter(querystring)
    modifier_sum = filter + modifier + include


if __name__ == '__main__':
    async for r in s.iterate('orders'):
        print(r)

SyntaxError: 'async with' outside async function

oefterdal avatar Sep 12 '22 12:09 oefterdal