Looking at Jupyter Notebook use give me the hint for the solution.

    from gql.transport.requests import RequestsHTTPTransport

    _transport = RequestsHTTPTransport(
        url="https://countries.trevorblades.com/";,
        use_json=True,
    )

Issue solved :)

Richard

On Wednesday, July 29, 2020 at 3:57:33 PM UTC+2, Richard D wrote:
>
> Dear Web2py friends,
>
> I am trying to cosume a graphql endpoint using 
> https://github.com/graphql-python/gql#HTTP-async-transport but get an 
> error.
>
> Applied code:
>
> def qlquery():
>     from gql import gql, Client, AIOHTTPTransport
>
>     # Select your transport with a defined url endpoint
>     transport = AIOHTTPTransport(url="https://countries.trevorblades.com/";
> )
>
>     # Create a GraphQL client using the defined transport
>     client = Client(transport=transport, fetch_schema_from_transport=True)
>
>     # Provide a GraphQL query
>     query = gql(
>         """
>         query getContinents {
>         continents {
>             code
>             name
>             }
>         }
>     """
>     )
>
>     # Execute the query on the transport
>     result = client.execute(query)
>     print(result)
>
>     return locals()
>
>
> Gives:
>
> class 'RuntimeError'> There is no current event loop in thread 'Thread-13'. 
> Versie 
> web2py™ Version 2.20.4-stable+timestamp.2020.05.03.05.18.50 
> Python Python 3.8.2: C:\Program Files\Python38\python.exe (prefix: 
> C:\Program Files\Python38) Traceback 
>
> 1.
> 2.
> 3.
> 4.
> 5.
> 6.
> 7.
> 8.
> 9.
> 10.
> 11.
> 12.
> 13.
> 14.
>
> Traceback (most recent call last):
>   File "E:\web2py_src\web2py\gluon\restricted.py", line 219, in restricted
>     exec(ccode, environment)
>   File "E:/web2py_src/web2py/applications/insp/controllers/qlquery.py" 
> <http://127.0.0.1:8000/admin/default/edit/insp/controllers/qlquery.py>, line 
> 27, in <module>
>   File "E:\web2py_src\web2py\gluon\globals.py", line 430, in <lambda>
>     self._caller = lambda f: f()
>   File "E:/web2py_src/web2py/applications/insp/controllers/qlquery.py" 
> <http://127.0.0.1:8000/admin/default/edit/insp/controllers/qlquery.py>, line 
> 23, in qlquery
>     result = client.execute(query)
>   File 
> "C:\Users\richa\AppData\Roaming\Python\Python38\site-packages\gql\client.py", 
> line 113, in execute
>     loop = asyncio.get_event_loop()
>   File "C:\Program Files\Python38\lib\asyncio\events.py", line 639, in 
> get_event_loop
>     raise RuntimeError('There is no current event loop in thread %r.'
> RuntimeError: There is no current event loop in thread 'Thread-13'.
>
>
> This looks like a asyncio issue as mentioned in 
> https://github.com/graphql-python/gql#HTTP-async-transport
> Here they suggest to use :
>
> from gql import gql, AIOHTTPTransport, Clientimport asyncio
> async def main():
>
>     transport = 
> AIOHTTPTransport(url='https://countries.trevorblades.com/graphql')
>
>     # Using `async with` on the client will start a connection on the 
> transport
>     # and provide a `session` variable to execute queries on this connection
>     async with Client(
>         transport=transport,
>         fetch_schema_from_transport=True,
>         ) as session:
>
>         # Execute single query
>         query = gql('''            query getContinents {              
> continents {                code                name              }           
>  }        ''')
>
>         result = await session.execute(query)
>         print(result)
> asyncio.run(main())
>
> But this 'hangs'
>
> Does anybody has some experience with this?
>
> Kind regards,
> Richard
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/52beeeb5-3e8c-415d-9f40-704dfdbd97a9o%40googlegroups.com.

Reply via email to